ruk·si

🐋 Docker
NVIDIA Image Building

Updated at 2017-02-21 13:07

Building a NVIDIA CUDA enabled 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.

    ssh user@xxx.xxx.xxx.xxx
    
  2. 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...
    
  3. Create a Dockerfile after you get it in the state you want.

    FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04
    MAINTAINER Ruksi <me@ruk.si>
    
    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 \
      git
    
    RUN git clone https://github.com/pjreddie/darknet.git /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
    
    ENTRYPOINT []
    CMD ["/bin/bash"]
    
  4. Build the image

    # Check latest commit id at https://github.com/pjreddie/darknet
    b61bcf5
    
    # 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