🐋 Docker
nvidia-docker Image Building

Updated at 2017-02-21 13:07

Building a NVIDIA CUDA enable Docker image. I'll be building an image to run darknet machine learning library in this example.

  1. Connect to a build machine with working nvidia-docker if you don't have it locally.
  1. Try out your hypothesis how to build the image; base image, commands, etc.
nvidia-docker pull nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04
nvidia-docker history nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04
nvidia-docker rm `nvidia-docker ps -aq`
nvidia-docker run -it --rm --name cccc nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04 /bin/bash
# try out what you plan on doing...
  1. Create a Dockerfile after you get it in the state you want.
FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 CUDA_ROOT=/usr/local/cuda/bin

RUN apt-get update --fix-missing && apt-get install -y \
  libopencv-dev \
  python-opencv \

RUN git clone /darknet
WORKDIR /darknet
RUN sed -i'' -- 's/GPU=0/GPU=1/g' Makefile
RUN sed -i'' -- 's/CUDNN=0/CUDNN=1/g' Makefile
RUN sed -i'' -- 's/OPENCV=0/OPENCV=1/g' Makefile
RUN make

CMD ["/bin/bash"]
  1. Build the docker image
# Check latest commit id at

# Build the Dockerfile to an image.
nvidia-docker build -t ruksi/darknet:gpu-b61bcf5 .

# Check that it works.
nvidia-docker run --rm ruksi/darknet:gpu-b61bcf5 /darknet/darknet
# => usage: /darknet/darknet <function>

# Push to Docker repository.
`aws ecr get-login --region eu-west-1` # if required for access
nvidia-docker push ruksi/darknet:gpu-b61bcf5