官网文档说明
- 进入官网文档
- 找到下载安装文档
- 选择centos
docker 安装
卸载docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
[vagrant@localhost ~]$ sudo yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
安装yum-utils包
sudo yum install -y yum-utils
[vagrant@localhost ~]$ sudo yum install -y yum-utils
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 242 kB 00:00:01
(3/4): base/7/x86_64/primary_db | 6.1 MB 00:00:03
(4/4): updates/7/x86_64/primary_db | 8.8 MB 00:00:06
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-53.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Updating:
yum-utils noarch 1.1.31-54.el7_8 base 122 k
Transaction Summary
========================================================================================================================
Upgrade 1 Package
Total download size: 122 k
Downloading packages:
No Presto metadata available for base
warning: /var/cache/yum/x86_64/7/base/packages/yum-utils-1.1.31-54.el7_8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for yum-utils-1.1.31-54.el7_8.noarch.rpm is not installed
yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : yum-utils-1.1.31-54.el7_8.noarch 1/2
Cleanup : yum-utils-1.1.31-53.el7.noarch 2/2
Verifying : yum-utils-1.1.31-54.el7_8.noarch 1/2
Verifying : yum-utils-1.1.31-53.el7.noarch 2/2
Updated:
yum-utils.noarch 0:1.1.31-54.el7_8
Complete!
设置docker 下载地址
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
[vagrant@localhost ~]$ sudo yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
安装最新版本的 Docker Engine 和 containerd
sudo yum install docker-ce docker-ce-cli containerd.io
安装时默认输入y
[vagrant@localhost ~]$ sudo yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/primary_db | 62 kB 00:00:00
(2/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.6-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.4.6-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:20.10.7-3.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.7-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-20.10.7-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.7-3.el7 will be installed
--> Processing Dependency: docker-scan-plugin(x86-64) for package: 1:docker-ce-cli-20.10.7-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.119.2-1.911c772.el7_8.noarch
---> Package docker-ce-rootless-extras.x86_64 0:20.10.7-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.7-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.7-3.el7.x86_64
---> Package docker-scan-plugin.x86_64 0:0.8.0-3.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
--> Running transaction check
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package policycoreutils-python.x86_64 0:2.5-34.el7 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================== Package Arch Version Repository Size
========================================================================================================================Installing:
containerd.io x86_64 1.4.6-3.1.el7 docker-ce-stable 34 M
docker-ce x86_64 3:20.10.7-3.el7 docker-ce-stable 27 M
docker-ce-cli x86_64 1:20.10.7-3.el7 docker-ce-stable 33 M
Installing for dependencies:
audit-libs-python x86_64 2.8.5-4.el7 base 76 k
checkpolicy x86_64 2.5-8.el7 base 295 k
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
docker-ce-rootless-extras x86_64 20.10.7-3.el7 docker-ce-stable 9.2 M
docker-scan-plugin x86_64 0.8.0-3.el7 docker-ce-stable 4.2 M
fuse-overlayfs x86_64 0.7.2-6.el7_8 extras 54 k
fuse3-libs x86_64 3.6.1-4.el7 extras 82 k
libcgroup x86_64 0.41-21.el7 base 66 k
libsemanage-python x86_64 2.5-14.el7 base 113 k
policycoreutils-python x86_64 2.5-34.el7 base 457 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.8-4.el7 base 620 k
slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k
Transaction Summary
========================================================================================================================Install 3 Packages (+13 Dependent packages)
Total download size: 108 M
Installed size: 444 M
Is this ok [y/d/N]: y
Downloading packages:
(1/16): audit-libs-python-2.8.5-4.el7.x86_64.rpm | 76 kB 00:00:00
(2/16): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00
(3/16): checkpolicy-2.5-8.el7.x86_64.rpm | 295 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.7-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-20.10.7-3.el7.x86_64.rpm is not installed
(4/16): docker-ce-20.10.7-3.el7.x86_64.rpm | 27 MB 00:00:23
(5/16): containerd.io-1.4.6-3.1.el7.x86_64.rpm | 34 MB 00:00:24
(6/16): docker-ce-rootless-extras-20.10.7-3.el7.x86_64.rpm | 9.2 MB 00:00:06
(7/16): libcgroup-0.41-21.el7.x86_64.rpm | 66 kB 00:00:00
(8/16): libsemanage-python-2.5-14.el7.x86_64.rpm | 113 kB 00:00:00
(9/16): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00
(10/16): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00
(11/16): docker-scan-plugin-0.8.0-3.el7.x86_64.rpm | 4.2 MB 00:00:02
(12/16): policycoreutils-python-2.5-34.el7.x86_64.rpm | 457 kB 00:00:02
(13/16): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:00
(14/16): setools-libs-3.3.8-4.el7.x86_64.rpm | 620 kB 00:00:02
(15/16): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:05
(16/16): docker-ce-cli-20.10.7-3.el7.x86_64.rpm | 33 MB 00:00:19
------------------------------------------------------------------------------------------------------------------------Total 2.5 MB/s | 108 MB 00:00:42
Retrieving key from https://download.docker.com/linux/centos/gpg
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://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libcgroup-0.41-21.el7.x86_64 1/16
Installing : 1:docker-ce-cli-20.10.7-3.el7.x86_64 2/16
Installing : docker-scan-plugin-0.8.0-3.el7.x86_64 3/16
Installing : setools-libs-3.3.8-4.el7.x86_64 4/16
Installing : python-IPy-0.75-6.el7.noarch 5/16
Installing : slirp4netns-0.4.3-4.el7_8.x86_64 6/16
Installing : libsemanage-python-2.5-14.el7.x86_64 7/16
Installing : audit-libs-python-2.8.5-4.el7.x86_64 8/16
Installing : fuse3-libs-3.6.1-4.el7.x86_64 9/16
Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64 10/16
Installing : checkpolicy-2.5-8.el7.x86_64 11/16
Installing : policycoreutils-python-2.5-34.el7.x86_64 12/16
Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 13/16
Installing : containerd.io-1.4.6-3.1.el7.x86_64 14/16
Installing : docker-ce-rootless-extras-20.10.7-3.el7.x86_64 15/16
Installing : 3:docker-ce-20.10.7-3.el7.x86_64 16/16
Verifying : containerd.io-1.4.6-3.1.el7.x86_64 1/16
Verifying : checkpolicy-2.5-8.el7.x86_64 2/16
Verifying : fuse3-libs-3.6.1-4.el7.x86_64 3/16
Verifying : audit-libs-python-2.8.5-4.el7.x86_64 4/16
Verifying : docker-scan-plugin-0.8.0-3.el7.x86_64 5/16
Verifying : libsemanage-python-2.5-14.el7.x86_64 6/16
Verifying : slirp4netns-0.4.3-4.el7_8.x86_64 7/16
Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 8/16
Verifying : python-IPy-0.75-6.el7.noarch 9/16
Verifying : policycoreutils-python-2.5-34.el7.x86_64 10/16
Verifying : 3:docker-ce-20.10.7-3.el7.x86_64 11/16
Verifying : 1:docker-ce-cli-20.10.7-3.el7.x86_64 12/16
Verifying : setools-libs-3.3.8-4.el7.x86_64 13/16
Verifying : docker-ce-rootless-extras-20.10.7-3.el7.x86_64 14/16
Verifying : fuse-overlayfs-0.7.2-6.el7_8.x86_64 15/16
Verifying : libcgroup-0.41-21.el7.x86_64 16/16
Installed:
containerd.io.x86_64 0:1.4.6-3.1.el7 docker-ce.x86_64 3:20.10.7-3.el7 docker-ce-cli.x86_64 1:20.10.7-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 docker-ce-rootless-extras.x86_64 0:20.10.7-3.el7 docker-scan-plugin.x86_64 0:0.8.0-3.el7
fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 libcgroup.x86_64 0:0.41-21.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7
python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8
Complete!
启动docker
[vagrant@localhost ~]$ sudo systemctl start docker
验证docker
- 查看docker 版本
[vagrant@localhost ~]$ docker -v
Docker version 20.10.7, build f0df350
- 查看docker 镜像
[vagrant@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
设置docker 开机自启动
[vagrant@localhost ~]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
设置docker镜像加速
- 阿里云中找到镜像加速配置
- 执行镜像加速配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://2fys4xe4.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
[vagrant@localhost ~]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[vagrant@localhost ~]$ sudo mkdir -p /etc/docker
o tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://2fys4xe4.mirror.aliyuncs.com"]
}
EOF
su[vagrant@localhost ~]$ sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://2fys4xe4.mirror.aliyuncs.com"]
> }
> EOF
do systemctl daemon-reload{
"registry-mirrors": ["https://2fys4xe4.mirror.aliyuncs.com"]
}
[vagrant@localhost ~]$ sudo systemctl daemon-reload
[vagrant@localhost ~]$ sudo systemctl restart docker