目录

Centos系统安装Docker

用最便捷的脚本来满足你的需求

Waring

2024年6月,国内几家Docker Hub 镜像服务平台均被要求下架,停止服务。

中科大镜像源 2024-06-06 ,暂时关闭 Docker Hub 镜像缓存服务,GCR 与 Quay 暂不受影响

在线安装

1. 更新yum源

yum update 

2. 更新yum-utils源

yum install -y yum-utils

3. 安装docker

yum install -y docker

4. 安装docker-compose

使用到docker-compose.yml部署项目时需要安装此功能

4.1 添加docker的yum镜像源

yum-config-manager  --add-repo  https://download.docker.com/linux/centos/docker-ce.repo

4.2 安装docker插件

yum -y install docker-compose-plugin

离线安装

本教程采用二进制安装

1.下载docker离线包

如果您还未下载离线包,请点击👉 下载Docker离线包 24.0.5版本。

若想下载其他版本请至官网下载 https://download.docker.com/linux/static/stable/x86_64/ (需要🔮)

2.解压离线包

tar xvf docker-24.0.5.tgz.tar

3.将解压的docker拷贝或移动到/usr/bin/目录下

cp docker/* /usr/bin/

4.编写docker.service 文件加入Linux服务当中并开启守护进程

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 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

5.添加文件可执行权限

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

6.配置成功后,重新加载 daemon 服务

systemctl daemon-reload

7.启动 docker 服务

systemctl start docker

卸载

常见问题

镜像拉取失败

设置镜像源地址

mkdir -p /etc/docker;
vi /etc/docker/daemon.json

文件内容

{
    "registry-mirrors":
    [
        "https://ustc-edu-cn.mirror.aliyuncs.com/",
        "https://ccr.ccs.tencentyun.com/",
        "https://docker.m.daocloud.io/"
    ]
}

重启docker

sudo systemctl daemon-reload		#重启daemon进程
sudo systemctl restart docker		#重启docker