Skip to content

Instantly share code, notes, and snippets.

@Merwanski
Created November 25, 2021 15:13
Show Gist options
  • Save Merwanski/f4a145db39c8e00f1e9c30e406bc212d to your computer and use it in GitHub Desktop.
Save Merwanski/f4a145db39c8e00f1e9c30e406bc212d to your computer and use it in GitHub Desktop.
tensorflow/tensorflow:latest-gpu-py3 docker container to start with dev machine
Create a new container from the TensorFlow image
"""
$ docker run -it --rm tensorflow/tensorflow:latest-gpu-py3
"""
You should be logged-in in the new container. You can explore it using ls, cd, etc…
You can exit using
$ exit.
Create a directory to exchange files between your machine and the container:
"""
$ mkdir ~/docker_share
$ docker run -u $(id -u):$(id -g) --gpus all -it --rm --name my_tf_container -v ~/docker_share:~/docker_share -p 8888:8888 -p 6006:6006 tensorflow/tensorflow:latest-gpu-py3-jupyter
"""
To get extra and display add the following
"""
--device /dev/video0 --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw"
"""
Let’s explain the different options.
-u $(id -u):$(id -g) # assign a user and a group ID
--gpus all # allow GPU support
-it # run an interactive container inside a terminal
-rm # automatically clean up the container and remove the file system after closing the container
--name my_tf_container # give it a friendly name
-v ~/docker_ws:/notebooks # share a directory between the host and the container
-p 8888:8888 # define port 8888 to connect to the container
-p 6006:6006 # forward port 6006 for Tensorboard
Once the container is running, your should see a URL to copy and paste in your browser that looks
like “http://127.0.0.1:8888/?token=xxxxxxxxxx”.
Finally, you can use "docker exec" to run a command inside a running docker container.
In another terminal, run this command:
"""
$ docker exec -it my_tf_container tensorboard --logdir tf_logs/
"""
You should be able to access the TensorBoard page via this URL “http://localhost:6006/”
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment