11. GPU
In some application, you may need Graphics Processing Unit GPU
support with NVIDIA graphics card. NVIDIA has published the NVIDIA Container Toolkit
to enable GPU support for Docker containers. The GitHub site has information on how to install this tool nvidia-docker
.
To see if you have installed nvidia-docker
correctly, type in the following.
1docker run --gpus all nvidia/cuda:9.0-base nvidia-smi
You should see an output similar to the below.
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.50 Driver Version: 430.50 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce RTX 208... Off | 00000000:01:00.0 On | N/A |
| 25% 33C P8 17W / 250W | 893MiB / 11016MiB | 5% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
The Dockerfile
uses nvidia/cuda:10.0-cudnn7-devel
as the base image. We install conda
and the PyTorch
packages, and we use supervisor
to start up Jupyter Lab.
1FROM nvidia/cuda:10.0-cudnn7-devel
2
3ENV DEBIAN_FRONTEND=noninteractive
4ENV CONDA_HOME="/opt/anaconda"
5ENV PATH="${CONDA_HOME}/bin:${PATH}"
6ENV JUPYTER_TYPE=lab
7
8# update OS
9RUN apt-get update -y && \
10 apt-get upgrade -y && \
11 apt-get install wget supervisor -y
12
13# setup supervisor
14COPY jupyter.conf /etc/supervisor/conf.d/
15
16# install conda
17RUN wget -q https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh -O /tmp/anaconda.sh && \
18 /bin/bash /tmp/anaconda.sh -b -p $CONDA_HOME
19
20# install python packages
21RUN conda install pytorch torchvision cudatoolkit=10.0 -y -c pytorch
22
23# setup mount point
24VOLUME ["/ipynb"]
25
26# setup ports
27EXPOSE 8888
28
29# clean up
30RUN apt-get clean && \
31 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
32
33CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf", "-n"]
Build.
1docker build --no-cache -t gpu-jupyter:local .
Run. Note that we have to specify the --gpus all
flag to give GPU access to the container.
1docker run \
2 -it \
3 --rm \
4 -p 8888:8888 \
5 --gpus all \
6 -v `pwd`/ipynb:/ipynb \
7 gpu-jupyter:local
You may now access the Jupyter Lab at http://localhost:8888.