Skip to content

Instantly share code, notes, and snippets.

@minlaxz
Last active November 5, 2020 08:54
Show Gist options
  • Save minlaxz/ab10afa935fc97fe264b08e50f5540ea to your computer and use it in GitHub Desktop.
Save minlaxz/ab10afa935fc97fe264b08e50f5540ea to your computer and use it in GitHub Desktop.
  1. Install Docker Guide
  2. Test Docker
  • $ sudo usermod -aG docker $USER . (Add USER to Docker Group)
  • $ docker run hello-world
  1. Setting up NVIDIA Container Toolkit
  • $ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
  • $ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
  • $ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
  1. Install Nvidia-Docker2
  • $ sudo apt install -y nvidia-docker2
  • $ sudo systemctl restart docker
  1. Test Docker2
  • $ sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi
  1. Example Pull Tensorflow
  • $ docker pull tensorflow/tensorflow # latest stable release OR
  • $ docker pull tensorflow/tensorflow:latest-gpu-jupyter # latest release w/ GPU support and Jupyter
  1. Example Run Tensorlfow Docker
  • $ docker run [-it] [--rm] [-p hostPort:containerPort] tensorflow/tensorflow[:tag] [command]
  1. Start Docker Tensorflow GPUs with Jupyter
  • $ docker run -it --rm -v ~/jupyters:/tf/notebooks -p 8888:8888 tensorflow/tensorflow:latest-jupyter

Example-1

$ docker run --gpus all -it --rm -v ~/jupyters:/tf/notebooks -p 8888:8888 tensorflow/tensorflow:latest-jupyter

  • docker run -- will run command in new container
  • -it -- interactive and allocate tty
  • --rm -- will auto remove container when it exits
  • -v -- mounting volume (I am mounting my jupyters folder under HOME to /tf/notebooks in jupyter)
  • -p -- publish caontainer's port(s) to host
  • last one is Image I've downloaded from dockerhub.

Example-2

Let's create a cotainter first for later uses.
$ docker run --name tfdk --gpus all -dt -v ~/jupyters:/tf/notebooks -p 8888:8888 tensorflow/tensorflow:latest-jupyter

  • docker run -- will run command in new container
  • -dt -- detach (run background and print container ID) and allocate tty
  • -v -- mounting volume (I am mounting my jupyters folder under HOME to /tf/notebooks in jupyter)
  • -p -- publish caontainer's port(s) to host
  • last one is Image I've downloaded from dockerhub.

Open browser and visit localhost:8888 cuz conatiner is forwarding to port your_host:8888.
It will ask you token or password for jupyter for the first time. $ docker exex -it tfdk notebook list
You can get interactive shell $ docker exex -it tfdk /bin/bash
Quit Jupyter server or $ docker stop tfdk will stop docker from running.
For next time just type $ docker start tfdk and visit your host localhost:8888.

Ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment