1

I just got a Mac and shifted from Windows and installed Tensorflow using Docker and everything is working fine, but I want to run a python script that I have from before. Is there any way to run a python script in docker on a Mac, using the terminal?

2
  • 1
    you need to add more info in order to give a better response. The assumption is that you build a docker image with Tensorflow, in that case; How are you building your docker image? is the python script in some repository or on your local machine? and what python version was the script built on (2.x/3.x)? Commented Feb 8, 2017 at 15:36
  • I am using the command docker run -it -p 8888:8888 tensorflow/tensorflow, and the script is on my local machine, and am using Python 2.x Commented Feb 8, 2017 at 16:18

3 Answers 3

2

More information would be very helpful, but perhaps this is useful for you.

It depends on a lot of different factors, but assuming a couple of things:

The docker containing Tensorflow has a name like 'tensorflow' already contains the python script: you can use: docker run tensorflow 'python '

If the script is not yet present, you can either use build a docker based on that image using a docker file, something along the lines of:

FROM tensorflow:latest
ADD /some/local/path.py /the/path/on/my/docker

Or you can create/run the docker interactively by doing something along the lines of:

Docker run -ti tensorflow /bin/bash Which will start an instance of the tensorflow container and start /bin/bash on it. You now have an interactive shell so can place the python script any way you want and start it.

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

1 Comment

Once I enter docker run -it tensorflow/tensorflow /bin/bash, how do I enter the python script that I want to run?
2

Lets assume you have a script my_script.py located at /Users/awesome_user/python_scripts/ on your mac

By default the tensorFlow image bash will locate you at /notebooks.

Run this command in your terminal:

docker run --rm -it -v /Users/awesome_user/python_scripts/:/notebooks gcr.io/tensorflow/tensorflow bash

This will map your local mac folder /Users/awesome_user/python_scripts/ to the docker's local folder /notebooks

then just run from the bash python my_script.py. Also running ls should reveal your folder content

1 Comment

Obviously, feel free to replace /notebooks with whatever local docker folder :)
1

Something like the below should do...

Create a Dockerfile with the below content:

FROM gcr.io/tensorflow/tensorflow:latest
COPY script.py /usr/bin/
CMD ["python", "/usr/bin/script.py"]

build the image:

$ docker build -t mytensorflow .

run it:

$ docker run -it --rm mytensorflow

if you want to keep the container going after the script is run don't --rm it...

1 Comment

FROM gcr.io/tensorflow/tensorflow:latest returns FROM: can't read /var/mail/gcr.io/tensorflow/tensorflow:latest

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.