一、Centos环境安装Docker
本文目录
1.1 在线安装Docker
参考官方文档安装:https://docs.docker.com/engine/install/centos/
1、更新yum
yum update
2、安装工具包
sudo yum install -y yum-utils
3、设置镜像源
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
4、安装前卸载原有的docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
5、安装最新版本的docker ce
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
6、启动docker
sudo systemctl start docker
7、设置开机启动docker
sudo systemctl enable docker
8、安装好之后查看docker 版本
docker -v
9、配置容器镜像加速地址
# 需要确定/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
10、重载配置
sudo systemctl daemon-reload
11、重启Docker
sudo systemctl restart docker
12、验证是否可用
docker ps # 查询正在运行的容器列表
1.2 离线安装Docker
1、Docker下载到指定目录
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz
2、解压缩
# 解压下载的文件
tar xf docker-20.10.9.tgz
# 查看解压出的目录
# ls docker
containerd containerd-shim-runc-v2 docker docker-init runc
containerd-shim ctr dockerd docker-proxy
3、将解压出来的docker文件内容移动到 /usr/bin/ 目录下
cp docker/* /usr/bin/
4、将docker注册为service
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
5、启动Docker
chmod +x /etc/systemd/system/docker.service #添加文件权限并启动docker
systemctl daemon-reload #重载unit配置文件
systemctl start docker #启动Docker
systemctl enable docker.service #设置开机自启
6、验证
systemctl status docker #查看Docker状态
docker -v #查看Docker版本
docker info
1.3 快速安装Docker
详情请看(能一键安装docker):https://github.com/tech-shrimp/docker_installer