I have a python script that i am trying to get running correctly in a docker container. I am struggling with the CMD section of the DOCKERFILE.
I can get the script to run correctly from my terminal that shows the live updates continuously as per the code in the script by opening an interactive python console and then running the following commands
exec(open("coin_flip_demo_v1.0.py").read())
test = coin_flip_demo()
test._run_()
My DOCKERFILE looks like
FROM python:3.6
RUN mkdir src
ADD . /src/
RUN pip install pandas
WORKDIR /src/
EXPOSE 32768 32769 32770
CMD [ "python", "./coin_flip_demo_v1.0.py" ]
When i try to run the container it doesn't give any errors however when i run docker ps there are no containers showing
Just for reference
coin_flip_demo_v1.0.py is the script i am trying to run
coin_flip_demo is my main class in that script
_run_ is a module within the main class.
Let me know if you need any more info to solve this issue.
Thanks
-
Did you try to run the container with -it option?Sam Daniel– Sam Daniel2019年08月30日 21:29:52 +00:00Commented Aug 30, 2019 at 21:29
1 Answer 1
To run interactive processes in a container, you should start the container with -i -t option.
This allocates a tty for the container.
docker run -it <img>[:tag]
Also refer to the answers in this SO question.
Apart from the -it option.. you should also make your python script to directly run (as you have mentioned in the Dockerfile so)
Can you run the script directly from the terminal? like this
python ./coin_flip_demo_v1.0.py
If not add the following lines to the end of the python file
if __name__ == '__main__':
test = coin_flip_demo()
test._run_()