参考官方文档安装:https://docs.docker.com/engine/install/centos/
yum update
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 慢
## 阿里云镜像源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #快
##腾讯镜像源
sudo yum-config-manager --add-repo https://mirrors.cloud.tencent.com/dockerce/linux/centos/docker-ce.repo
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker
docker -v
# 需要确定/etc下面是否有docker这个文件夹,若没有则需要使用下面的命令进行创建
sudo mkdir -p /etc/docker
# 创建配置文件daemon.json 并写入一下内容
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://mirror.ccs.tencentyun.com"] # 可以替换成其他地址
}
EOF
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://docker.1panel.live",
"https://hub.rat.dev"
]
}
EOF
## 科大镜像:https://docker.mirrors.ustc.edu.cn
## 网易:http://hub-mirror.c.163.com
## 腾讯云:https://mirror.ccs.tencentyun.com
## 阿里云:https://<你的ID>.mirror.aliyuncs.com
sudo systemctl daemon-reload
sudo systemctl restart docker
docker ps # 查询正在运行的容器列表
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz
# 解压下载的文件
tar xf docker-20.10.9.tgz
# 查看解压出的目录
# ls docker
containerd containerd-shim-runc-v2 docker docker-init runc
containerd-shim ctr dockerd docker-proxy
cp docker/* /usr/bin/
cat /etc/systemd/system/docker.service
vi /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
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 #添加文件权限并启动docker
systemctl daemon-reload #重载unit配置文件
systemctl start docker #启动Docker
systemctl enable docker.service #设置开机自启
systemctl status docker #查看Docker状态
docker -v #查看Docker版本
docker info
详情请看(能一键安装docker):https://github.com/tech-shrimp/docker_installer