crackcell's dustbin home projects
首页 > 带GPU支持的Docker环境设置 > 正文

带GPU支持的Docker环境设置

Table of Contents

1 环境

  • CentOS 7

2 步骤

  1. 安装docker-ce。CentOS自带的docker和nvidia-docker2依赖关系不太兼容
    sudo yum remove docker \
               docker-common \
               docker-selinux \
               docker-engine
    
    sudo yum install -y yum-utils \
               device-mapper-persistent-data \
               lvm2
    
    sudo yum-config-manager \
               --add-repo \
               https://download.docker.com/linux/centos/docker-ce.repo
    
    sudo yum install docker-ce
    
  2. 设置docker镜像目录
    mkdir -p /opt/soft/docker/images
    
    sudo mkdir /etc/systemd/system/docker.service.d
    
    sudo nano /etc/systemd/system/docker.service.d/docker.conf # 内容见下面
    
    sudo systemctl daemon-reload
    
    sudo systemctl start docker
    

    docker.conf:

    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd --data-root=/opt/soft/docker/images
    
  3. 安装nvidia-docker2
    # If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
    sudo docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
    sudo yum remove nvidia-docker
    
    # Add the package repositories
    sudo curl -s -L https://nvidia.github.io/nvidia-docker/centos7/x86_64/nvidia-docker.repo | \
      sudo tee /etc/yum.repos.d/nvidia-docker.repo
    
    # Install nvidia-docker2 and reload the Docker daemon configuration
    sudo yum install -y nvidia-docker2
    sudo pkill -SIGHUP dockerd
    
    # Test nvidia-smi with the latest official CUDA image
    docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
    
  4. 设置非sudo使用docker
    sudo groupadd docker
    sudo gpasswd -a $USER docker
    

Date: Thu Dec 21 10:57:04 2017

Author: Menglong TAN

Created: 2018-01-01 Mon 17:26

Emacs 24.5.1 (Org mode 8.2.10)

Validate

Modified theme and code from Tom Preston-Werner.