centos7离线安装docker和nvidia-docker

一、环境

 因某些环境,不能联外网,所以使用docker yum源方法行不通,于是打算离线安装

 环境:contos7.3(内核需为3.10+)

cat /etc/redhat-release
# CentOS Linux release 7.3.1611 (Core)

下载:docker-18.06.3-ce.tar

二、安装步骤

1、卸载旧docker

a、停止正在运行的容器

docker stop $(docker ps -a -q)

b、删除所有的容器

docker rm $(docker ps -a -q)

c、删除所有的镜像

docker rmi $(docker images -q)

d、先查询下docker

 yum list installed| grep docker

e、执行卸载命令

yum -y remove  docker.x86_64   docker-client.x86_64  docker-common.x86_64 nvidia-docker.x86_64

f、执行删除已存在的镜像和容器(以实际情况而定)

rm -rf  /var/lib/docker

2、离线重装docker

a、docker压缩包

cd /usr/local/resource/docker
tar -xzvf docker-18.06.3-ce.tgz
mv  /usr/local/resource/docker/docker/*  /usr/bin/ # 将二进制文件移动到bin下

b、systemd docker.service

vim /etc/systemd/system/docker.service

然后将以下内容粘贴进去:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
   
[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 tcp://0.0.0.0:2375 -H unix://var/run/docker.sock --add-runtime=nvidia=/usr/bin/nvidia-container-runtime
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
   
[Install]
WantedBy=multi-user.target

授予执行权限:

chmod +x /etc/systemd/system/docker.service

然后:

systemctl daemon-reload   # 重载systemd下 xxx.service文件
systemctl start docker       # 启动Docker
systemctl enable docker.service   # 设置开机自启

测试是否成功:

systemctl status docker   # 查看Docker状态
docker -v # 查看Docker版本

3、离线安装nvidia-docker

前提,已经安装了docker 

a、在一台联网的机器上执行下面命令

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
 
yum install --downloadonly nvidia-docker2 --downloaddir=/tmp/nvidia

会得到这些 :

b、将以上安装包上传到无法联网的服务器

c、进入rpm包路径里执行

rpm -Uvh *.rpm --nodeps --force

 

解决

docker: Error response from daemon: Unknown runtime specified nvidia. 解决方法

参考地址:https://blog.csdn.net/weixin_32820767/article/details/80538510

你可能感兴趣的:(linux,docker,linux,centos)