How to run Python scripts on a Mac terminal using Docker with Tensorflow?

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

+1
source share
3 answers

Something like the bottom should be done ...

Create a Docker file with the contents below:

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

create image:

 $ docker build -t mytensorflow . 

run it:

 $ docker run -it --rm mytensorflow 

if you want to save the container after running the script, do not use it ...

+1
source

More information would be very helpful, but maybe it is useful for you.

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

A docker containing Tensorflow has a name like 'tensorflow', already contains a python script: you can use: docker run tenorflow 'python'

If the script does not exist yet, you can use the docker assembly based on this image using the docker file, something like strings

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

Or you can create / run dockers interactively by doing something line by line:

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

+2
source

Suppose you have a script my_script.py located in /Users/awesome_user/python_scripts/ on your mac

By default, the tensorFlow bash image will find you in the / notebook.

Run this command in terminal:

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

This will copy your local mac /Users/awesome_user/python_scripts/ folder to the docker /notebooks local folder

then just run python my_script.py from bash python my_script.py . Also, running ls should show the contents of your folder

+1
source

Source: https://habr.com/ru/post/1237766/


All Articles