# add the GPG key for the official Docker repository to the system
curl -fsSL | sudo apt-key add -

# add the Docker repository to APT sources
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

# update the package database with the Docker packages from the newly added repo
sudo apt-get update

# install from the Docker repo instead of the default Ubuntu 16.04 repo
apt-cache policy docker-ce

# install docker
sudo apt-get install -y docker-ce

# check if the docker daemon is running
sudo systemctl status docker

# add user to docker group
sudo usermod -aG docker ${USER}
su - ${USER}
id -nG


# Install nvidia-runtime
# Download nvidia-runtime packages
curl -s -L | \
  sudo apt-key add -
curl -s -L | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update

# Install nvidia-runtime
sudo apt-get install nvidia-container-runtime

# Docker Engine setup
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/override.conf <<EOF
ExecStart=/usr/bin/dockerd --host=fd:// --add-runtime=nvidia=/usr/bin/nvidia-container-runtime
sudo systemctl daemon-reload
sudo systemctl restart docker

# Daemon configuration file
sudo tee /etc/docker/daemon.json <<EOF
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
sudo pkill -SIGHUP dockerd

# Command line
sudo dockerd --add-runtime=nvidia=/usr/bin/nvidia-container-runtime [...]

# If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo apt-get purge -y nvidia-docker

# Add the package repositories
curl -s -L | \
  sudo apt-key add -
curl -s -L | \
  sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update

# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker
sudo pkill -SIGHUP dockerd

# Test nvidia-smi with the latest official CUDA image
docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi


sudo rm -rf /var/run/docker/
sudo rm -rf /etc/docker/
sudo apt-get purge -y docker-engine docker docker-ce

+ Recent posts