Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的Linux或Windows操作系统的机器上,也可以实现虚拟化。
切换到源目录,备份原来的源
[root@localhost data]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv CentOS-Linux-* bak
[root@localhost yum.repos.d]# ls
下载新的源文件,并用命令yum makecache建立新的元数据缓存
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-11-05 08:53:51-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 117.161.156.242, 117.161.156.239, 117.161.156.243, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|117.161.156.242|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2495 (2.4K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
/etc/yum.repos.d/CentOS-Base.repo 100%[=====================================================================>] 2.44K --.-KB/s in 0.02s
2022-11-05 08:53:53 (133 KB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2495/2495]
[root@localhost yum.repos.d]# ls
bak CentOS-Base.repo
[root@localhost yum.repos.d]# vim CentOS-Base.repo
[root@localhost yum.repos.d]# yum makecache
CentOS-8.5.2111 - Base - mirrors.aliyun.com 171 kB/s | 4.6 MB 00:27
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 35 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 139 kB/s | 8.4 MB 01:02
Metadata cache created.
测试源(用yum命令装个软件试试)
[root@localhost yum.repos.d]# yum install -y yum-utils
Last metadata expiration check: 0:08:11 ago on Sat 05 Nov 2022 08:55:50 AM CST.
Dependencies resolved.
===================================================================================================================================================
Package Architecture Version Repository Size
===================================================================================================================================================
Installing:
yum-utils noarch 4.0.21-3.el8 base 73 k
Transaction Summary
===================================================================================================================================================
Install 1 Package
Total download size: 73 k
Installed size: 22 k
Downloading Packages:
yum-utils-4.0.21-3.el8.noarch.rpm 15 kB/s | 73 kB 00:04
---------------------------------------------------------------------------------------------------------------------------------------------------
Total 15 kB/s | 73 kB 00:04
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : yum-utils-4.0.21-3.el8.noarch 1/1
Running scriptlet: yum-utils-4.0.21-3.el8.noarch 1/1
Verifying : yum-utils-4.0.21-3.el8.noarch 1/1
Installed:
yum-utils-4.0.21-3.el8.noarch
Complete!
设置镜像仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost yum.repos.d]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装 docker
[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Docker CE Stable - x86_64 51 kB/s | 31 kB 00:00
Dependencies resolved.
=============================================================================================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================================================================================
Installing:
containerd.io x86_64 1.6.9-3.1.el8 docker-ce-stable 33 M
docker-ce x86_64 3:20.10.21-3.el8 docker-ce-stable 21 M
docker-ce-cli x86_64 1:20.10.21-3.el8 docker-ce-stable 30 M
docker-compose-plugin x86_64 2.12.2-3.el8 docker-ce-stable 10 M
Installing dependencies:
container-selinux noarch 2:2.167.0-1.module_el8.5.0+911+f19012f9 AppStream 54 k
docker-ce-rootless-extras x86_64 20.10.21-3.el8 docker-ce-stable 4.6 M
fuse-overlayfs x86_64 1.7.1-1.module_el8.5.0+890+6b136101 AppStream 73 k
fuse3 x86_64 3.2.1-12.el8 base 50 k
fuse3-libs x86_64 3.2.1-12.el8 base 94 k
libslirp x86_64 4.4.0-1.module_el8.5.0+890+6b136101 AppStream 70 k
slirp4netns x86_64 1.1.8-1.module_el8.5.0+890+6b136101 AppStream 51 k
Installing weak dependencies:
docker-scan-plugin x86_64 0.21.0-3.el8 docker-ce-stable 3.8 M
Enabling module streams:
container-tools rhel8
Transaction Summary
=============================================================================================================================================================================================
Install 12 Packages
Total download size: 103 M
Installed size: 394 M
Is this ok [y/N]: y
Downloading Packages:
(1/12): fuse3-3.2.1-12.el8.x86_64.rpm 75 kB/s | 50 kB 00:00
(2/12): container-selinux-2.167.0-1.module_el8.5.0+911+f19012f9.noarch.rpm 76 kB/s | 54 kB 00:00
(3/12): fuse3-libs-3.2.1-12.el8.x86_64.rpm 82 kB/s | 94 kB 00:01
(4/12): libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64.rpm 80 kB/s | 70 kB 00:00
(5/12): fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64.rpm 78 kB/s | 73 kB 00:00
(6/12): slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64.rpm 86 kB/s | 51 kB 00:00
(7/12): docker-ce-20.10.21-3.el8.x86_64.rpm 88 kB/s | 21 MB 04:05
(8/12): docker-ce-rootless-extras-20.10.21-3.el8.x86_64.rpm 86 kB/s | 4.6 MB 00:54
(9/12): docker-ce-cli-20.10.21-3.el8.x86_64.rpm 87 kB/s | 30 MB 05:48
(10/12): containerd.io-1.6.9-3.1.el8.x86_64.rpm 87 kB/s | 33 MB 06:26
(11/12): docker-scan-plugin-0.21.0-3.el8.x86_64.rpm 86 kB/s | 3.8 MB 00:45
(12/12): docker-compose-plugin-2.12.2-3.el8.x86_64.rpm 86 kB/s | 10 MB 02:02
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 247 kB/s | 103 MB 07:05
Docker CE Stable - x86_64 3.7 kB/s | 1.6 kB 00:00
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
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : docker-scan-plugin-0.21.0-3.el8.x86_64 1/12
Running scriptlet: docker-scan-plugin-0.21.0-3.el8.x86_64 1/12
Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch 2/12
Installing : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch 2/12
Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch 2/12
Installing : containerd.io-1.6.9-3.1.el8.x86_64 3/12
Running scriptlet: containerd.io-1.6.9-3.1.el8.x86_64 3/12
Installing : docker-ce-cli-1:20.10.21-3.el8.x86_64 4/12
Running scriptlet: docker-ce-cli-1:20.10.21-3.el8.x86_64 4/12
Installing : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64 5/12
Installing : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64 6/12
Installing : fuse3-libs-3.2.1-12.el8.x86_64 7/12
Running scriptlet: fuse3-libs-3.2.1-12.el8.x86_64 7/12
Installing : fuse3-3.2.1-12.el8.x86_64 8/12
Installing : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64 9/12
Running scriptlet: fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64 9/12
Installing : docker-ce-3:20.10.21-3.el8.x86_64 10/12
Running scriptlet: docker-ce-3:20.10.21-3.el8.x86_64 10/12
Installing : docker-ce-rootless-extras-20.10.21-3.el8.x86_64 11/12
Running scriptlet: docker-ce-rootless-extras-20.10.21-3.el8.x86_64 11/12
Installing : docker-compose-plugin-2.12.2-3.el8.x86_64 12/12
Running scriptlet: docker-compose-plugin-2.12.2-3.el8.x86_64 12/12
Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch 12/12
Running scriptlet: docker-compose-plugin-2.12.2-3.el8.x86_64 12/12
Verifying : fuse3-3.2.1-12.el8.x86_64 1/12
Verifying : fuse3-libs-3.2.1-12.el8.x86_64 2/12
Verifying : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch 3/12
Verifying : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64 4/12
Verifying : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64 5/12
Verifying : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64 6/12
Verifying : containerd.io-1.6.9-3.1.el8.x86_64 7/12
Verifying : docker-ce-3:20.10.21-3.el8.x86_64 8/12
Verifying : docker-ce-cli-1:20.10.21-3.el8.x86_64 9/12
Verifying : docker-ce-rootless-extras-20.10.21-3.el8.x86_64 10/12
Verifying : docker-compose-plugin-2.12.2-3.el8.x86_64 11/12
Verifying : docker-scan-plugin-0.21.0-3.el8.x86_64 12/12
Installed:
container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch containerd.io-1.6.9-3.1.el8.x86_64 docker-ce-3:20.10.21-3.el8.x86_64
docker-ce-cli-1:20.10.21-3.el8.x86_64 docker-ce-rootless-extras-20.10.21-3.el8.x86_64 docker-compose-plugin-2.12.2-3.el8.x86_64
docker-scan-plugin-0.21.0-3.el8.x86_64 fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64 fuse3-3.2.1-12.el8.x86_64
fuse3-libs-3.2.1-12.el8.x86_64 libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64 slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64
Complete!
启动Docker
sudo systemctl start docker
测试
[root@localhost ~]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:e18f0a777aefabe047a671ab3ec3eed05414477c951ab1a6f352a06974245fe7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
配置阿里云镜像加速器
登录阿里云
阿里云控制台首页 (aliyun.com)
打开控制台
点击展开
下滑找到容器镜像服务
输入指令
输入指令进行测试
sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
常用命令
启动docker
systemctl start docker
停止docker
systemctl stop docker
查看docker状态
systemctl status docker
重启
systemctl restart docker
开机启动
systemctl enable docker
查看信息
docker info
查看帮助文档
docker --help