Tensorflow-gpu 도커 이미지 빌드

아래와 같이 빌드하고 실행해봤는데, 결국 Tutorial 페이지 (https://www.tensorflow.org/install/install_linux)와 동일한 내용임. 그래도 나중에 버전이 바뀌거나 뭔가 수정할때는 저런식으로 하면 됨.

Install Docker (https://ahnbk.com/?p=87) and  install graphics driver

$ wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
$ sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
$ sudo apt-get update
$ sudo apt-get install cuda-9-0

make Dockerfile

$ mkdir ~/tmp
$ cd ~/tmp
$ vi Dockerfile
FROM nvidia/cuda:9.0-cudnn7-devel

RUN apt-get update && apt-get install -y python-pip
RUN pip install -U tensorflow-gpu==1.5.0
RUN pip install -U jupyter

RUN mkdir -p /workspace
RUN ln -s /usr/local/cuda/targets/x86_64-linux/lib/stubs/libcuda.so /usr/lib/libcuda.so.1

CMD tensorboard --logdir=/tmp &

VOLUME ["/workspace"]
WORKDIR /workspace
CMD jupyter notebook --ip= --no-browser --allow-root


Build docker image

$ docker build --network=host -t my_tensorflow_gpu .

Check generated image

$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my_tensorflow_gpu   latest              8572747862ff        39 minutes ago      4.05GB
nvidia/cuda         9.0-cudnn7-devel    b60a0d6ee5ab        2 weeks ago         2.73GB

Make directory on host to share with docker

$ mkdir ~/tensorflow_ws
$ docker run -it --runtime=nvidia -p 8888:8888 -p 6006:6006 -v /home/byeongkyu/tensorflow_ws:/workspace my_tensorflow_gpu

[I 04:30:25.958 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 04:30:26.134 NotebookApp] Serving notebooks from local directory: /workspace
[I 04:30:26.134 NotebookApp] 0 active kernels
[I 04:30:26.134 NotebookApp] The Jupyter Notebook is running at:
[I 04:30:26.134 NotebookApp]
[I 04:30:26.134 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 04:30:26.135 NotebookApp] 
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:

Run web browser, and connect to

token id changes when docker run.

New, do your job and save

Looks good, check the logs

2018-02-15 04:45:05.631210: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-02-15 04:45:05.824609: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1105] Found device 0 with properties: 
name: Quadro P6000 major: 6 minor: 1 memoryClockRate(GHz): 1.645
pciBusID: 0000:03:00.0
totalMemory: 23.87GiB freeMemory: 23.14GiB
2018-02-15 04:45:05.824641: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: Quadro P6000, pci bus id: 0000:03:00.0, compute capability: 6.1)