1.Docker安装
1.1 删除旧的Docker版本(待验证,在新创建的虚拟机里安装的,没有这步操作)
[root@bogon ~]# sudo dnf remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
[root@bogon ~]# sudo yum remove docker*
1.2 使用安装脚本自动安装
官方安装脚本
[root@bogon ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
国内 daocloud 一键安装命令(待验证,官方脚本可正常使用,,可跳过)
[root@bogon ~]# curl -sSL https://get.daocloud.io/docker | sh
1.2.1 官方安装脚本记录
[root@bogon ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# Executing docker install script, commit: e5543d473431b782227f8908005543bb4389b8de
+ sh -c 'yum install -y -q yum-utils'
+ sh -c 'yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo'
Loaded plugins: fastestmirror
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/13): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
(2/13): docker-ce-stable/7/x86_64/filelists_db | 64 kB 00:00:00
(3/13): base/7/x86_64/other_db | 2.6 MB 00:00:00
(4/13): docker-ce-stable/7/x86_64/other_db | 144 kB 00:00:00
(5/13): epel/x86_64/prestodelta | 1.7 kB 00:00:00
(6/13): docker-ce-stable/7/x86_64/primary_db | 148 kB 00:00:00
(7/13): extras/7/x86_64/filelists_db | 305 kB 00:00:00
(8/13): base/7/x86_64/filelists_db | 7.2 MB 00:00:06
(9/13): extras/7/x86_64/other_db | 154 kB 00:00:05
(10/13): updates/7/x86_64/other_db | 1.6 MB 00:00:01
(11/13): epel/x86_64/other_db | 4.1 MB 00:00:08
(12/13): epel/x86_64/filelists_db | 14 MB 00:00:14
(13/13): updates/7/x86_64/filelists_db | 14 MB 00:00:16
Metadata Cache Created
+ sh -c 'yum install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin'
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.14.0-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-buildx-plugin-0.14.0-1.el7.x86_64.rpm is not installed
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <docker@docker.com>"
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
setsebool: SELinux is disabled.
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
[root@bogon ~]#
[root@bogon ~]#
[root@bogon ~]# docker version
Client: Docker Engine - Community
Version: 26.1.2
API version: 1.45
Go version: go1.21.10
Git commit: 211e74b
Built: Wed May 8 14:01:02 2024
OS/Arch: linux/amd64
Context: default
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@bogon ~]#
1.3 使用yum安装(待验证,使用官方安装脚本安装的,可跳过)
1.3.1、设置Docker yum源
[root@bogon ~]# sudo yum install -y yum-utils
[root@bogon ~]# sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
1.3.2 安装最新的Docker engine
sudo yum install docker-ce docker-ce-cli containerd.io
1.3.2.1 安装指定版本Docker engine
#找到所有可用docker版本列表
yum list docker-ce --showduplicates | sort -r
# 安装指定版本,用上面的版本号替换<VERSION_STRING>
sudo yum install docker-ce-<VERSION_STRING>.x86_64 docker-ce-cli-
<VERSION_STRING>.x86_64 containerd.io
#例如:
#yum install docker-ce-3:20.10.5-3.el7.x86_64 docker-ce-cli-3:20.10.5-
3.el7.x86_64 containerd.io
#注意加上 .x86_64 大版本号
1.4 docker启动服务
systemctl start docker
systemctl enable docker
1.5 镜像加速
- 科大镜像:docker.mirrors.ustc.edu.cn/
- 网易:hub-mirror.c.163.com/
- 阿里云:https://<你的ID>.mirror.aliyuncs.com
- 七牛云加速器:reg-mirror.qiniu.com
以阿里云为例:
官方镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://bbq6yc2w.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker