Centos7.9 离线安装docker

 下载文件包并上传到服务器

https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-27.4.0.tgz

解压安装


[root@localhost ~]# tar -xf docker-27.4.0.tgz
[root@localhost ~]# cp docker/* /usr/local/bin/ 
[root@localhost ~]# docker -v

[root@localhost ~]# docker -h

 

将docker注册为 Systemd 的 service    /usr/lib/systemd/system/docker.service

[root@localhost ~]# cat > /usr/lib/systemd/system/docker.service <<EOF
[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/local/bin/dockerd -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536
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
 
EOF

#添加文件可执行权限
[root@localhost ~]# chmod
+x /usr/lib/systemd/system/docker.service

#添加国内镜像加速(每次修改需重启 docker)

[root@localhost ~]# mkdir /etc/docker
[root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://dockerpull.com",
"https://docker.anyhub.us.kg",
"https://dockerhub.jobcher.com",
"https://dockerhub.icu",
"https://docker.awsl9527.cn",
"https://j4rowshi.mirror.aliyuncs.com"
]
}
EOF

#重载/开机自启
[root@localhost ~]# systemctl daemon-reload && systemctl restart docker
# 开机自启
[root@localhost ~]# systemctl enable docker
# 查看运行状态,active (running)运行中

systemctl status docker

测试 Docker

[root@localhost ~]# docker load -i hello-world.tar

[root@localhost ~]# docker run hello-world

[root@localhost ~]# docker images

若能正常输出以上信息,则说明安装成功。

posted @ 2025-01-06 18:43  xiao-jie-tian  阅读(487)  评论(0)    收藏  举报