Centos 7 上安装 Docker CE 及 Nvidia Docker

Centos 7 一键安装 Docker CE

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

yum remove -y docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
yum install -y yum-utils
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    #国内源 https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker

或者使用 rainbond 提供的快速命令

curl -sfL https://get.rainbond.com/install_docker | bash

https://rainbond.com/docs/installation/install-with-ui/

Centos 7 修改 Docker CE 数据目录

如果数据盘较小,可以修改 Docker 的默认存储目录

修改 /usr/lib/systemd/system/docker.service ,在 ExecStart 后面添加 --graph=/data/docker/lib

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph=/data/docker/lib

然后重启 docker

systemctl daemon-reload
systemctl restart docker

在 Centos 7 上安装 Nvidia Docker

yum-config-manager \
    --add-repo 
    https://nvidia.github.io/nvidia-docker/centos7/x86_64/nvidia-docker.repo
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum install -y nvidia-docker2

nvidia-docker2Docker CE 配置文件与使用方法相同