场景


在上面安装Docker时,CentOS是可以访问外网安装的。

如果是在内网服务器上,即这台服务器没法访问外网应该如何安装Docker。

注:

​​ 关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

首先下载docker的离线安装包

​https://download.docker.com/linux/static/stable/x86_64/​

CentOS7中离线安装Docker与卸载_docker

这里选择20.10.7下载

下载之后将其上传到服务器上某路径下进行解压

tar -zvxf docker-20.10.7.tgz

CentOS7中离线安装Docker与卸载_docker_02

解压之后将docker目录复制到/usr/bin目录下

cp docker/* /usr/bin/

然后新建一个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
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

将此文件复制到服务器上

这里是在本地Windows系统上新建文件然后使用xftp将其上传到CentOS服务器

CentOS7中离线安装Docker与卸载_docker_03

 

CentOS7中离线安装Docker与卸载_服务器_04

然后在服务器上将其复制到/etc/systemd/system/下

cp docker.service /etc/systemd/system/

添加文件权限

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

重新加载配置文件

systemctl daemon-reload

启动docker

systemctl start docker

验证docker版本

docker version

CentOS7中离线安装Docker与卸载_docker_05

 卸载Docker

停止docker服务

systemctl stop docker

删除配置文件

rm -f /etc/systemd/system/docker.service

删除docker文件

rm -rf /usr/bin/docker*

重新加载配置文件

systemctl daemon-reload

CentOS7中离线安装Docker与卸载_docker_06