ruk·si

☁️ AWS
EC2 nvidia-docker Setup

Updated at 2017-01-02 22:14

Install NVIDIA drivers on the host:

Check what driver version you want to install from NVIDIA Drivers.

For AWS G2 Instances:

Product Type        GRID
Product Series      GRID Series
Product             GRID K520
Operating System    Linux 64-bit
Language            English (US)
Recommended/Beta    Recommended/Certified

And pick the highest version number, it should work.
# Install building dependencies.
sudo yum install -y gcc kernel-devel-`uname -r`

# Download and install the driver version you checked earlier.
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/367.57/NVIDIA-Linux-x86_64-367.57.run
sudo /bin/bash ./NVIDIA-Linux-x86_64-367.57.run
# Follow the instructions shown on the installer.

# Try that it works.
nvidia-smi

Install Docker:

sudo yum install -y docker

Install NVIDIA Docker plugin:

# check which is the newest release:
wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.0-rc.3/nvidia-docker_1.0.0.rc.3_amd64.tar.xz
sudo tar --strip-components=1 -C /usr/bin -xvf /tmp/nvidia-docker*.tar.xz && rm /tmp/nvidia-docker*.tar.xz

# Activate NVIDIA docker plugin.
sudo -b nohup nvidia-docker-plugin > /tmp/nvidia-docker.log

# Try it out.
nvidia-docker run --rm nvidia/cuda nvidia-smi

# Deactivate the plugin for now.
sudo kill `pidof nvidia-docker-plugin`

Automatically start NVIDIA docker plugin on boot:

sudo vim /etc/rc.d/init.d/nvidia-docker
#!/bin/sh
#
# chkconfig: 345 80 20
# description: NVIDIA Docker plugin.

. /etc/rc.d/init.d/functions

name="nvidia-docker"
cmd="nohup /usr/bin/nvidia-docker-plugin > /tmp/nvidia-docker.log"

RETVAL=0

start() {
    echo "Starting $name"
    daemon $cmd &
    RETVAL=$?
    return $RETVAL
}

stop() {
    echo "Stopping $name"
    kill `pidof nvidia-docker-plugin`
    RETVAL=$?
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;

    stop)
        stop
        ;;

    restart)
        stop
        start
        ;;
esac

exit $RETVAL
sudo chkconfig --add nvidia-docker
sudo chkconfig --levels 0123456 nvidia-docker off
sudo chkconfig --levels 345 nvidia-docker on
chkconfig --list nvidia-docker
sudo chmod +x /etc/rc.d/init.d/nvidia-docker
sudo service nvidia-docker start

Sources