1

I need to use Tensorflow on my Windows machine. I have installed Docker, and following these two tutorials (https://runnable.com/docker/python/dockerize-your-python-application and https://civisanalytics.com/blog/engineering/2014/08/14/Using-Docker-to-Run-Python/), I am trying to run my Python script. My Dockerfile is nearly identical to the one in the first tutorial, except that instead of installing pystrich, I'm installing Tensorflow. I've successfully made a Docker image called python-stuff, and I've made a script called my_script.py which just imports Tensorflow and then prints Hello world.

When I run the command docker run python-stuff python my_script.py, I don't get any errrors, but the script does not produce any output. Any ideas?

EDIT: My Dockerfile:

FROM python:3
ADD my_script.py /
RUN pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp35-cp35m-linux_x86_64.whl
CMD ["python", "./my_script.py"]

Running docker logs python-stuff gives Error: No such container: python-stuff

3
  • 1
    Post your Dockerfile, docker logs of your container Commented Oct 17, 2016 at 12:00
  • 1
    python-stuff is the name of your image, not the container. Run docker ps --all and you'll see the IDs of all exited containers. Then run docker logs b6a11 - or whatever the ID of the most recent container starts with. Also: what output are you expecting? Does your script generate a file, or write to the console? Commented Oct 17, 2016 at 12:37
  • Ah ok. Running docker logs <id> produces nothing. The script just imports Tensorflow and prints "Hello world" to console. Commented Oct 17, 2016 at 13:12

3 Answers 3

3

I fixed it! The problem was simply the './' in the CMD line in the Dockerfile. Removing this and building it again solved the problem.

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to see inline output, try adding the --tty and --interactive (or -ti for short) options. This will give you the stdout from your container on the console, as well as interact via stdin with your script.

The other way to run is with --detach, which will run in the background. If you do this, you Docker will print the container ID to the console, and you can then run docker logs ${ID} (replacing ${ID} with the ID that was printed, to see the current output your script has written to stdout. If you want to avoid using the long, generated ID, you can add the --name foo option to your container, to add a name which can be used in commands like docker logs foo.

1 Comment

Thanks! However, I'm still not getting any output from my program. Not sure if it's running at all.
0

For running a Python script with Python Docker image the command is

$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python your-daemon-or-script.py

It can be generalized for any image and python script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.