yum方式安装Docker
1.查看Centos版本命令
[root@suzhongde suzhongde]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
这里CentOS Linux release 7.9.2009 (Core)的版本必须大于3.0
2.需要确保当前安装的CentOS系统可以上网
[root@suzhongde suzhongde]# ping www.baidu.com
PING www.a.shifen.com (163.177.151.109) 56(84) bytes of data.
64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=1 ttl=54 time=9.02 ms
64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=2 ttl=54 time=9.83 ms
64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=3 ttl=54 time=9.60 ms
64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=4 ttl=54 time=9.77 ms
3.使用yum安装gcc相关依赖
# 在终端依次输入以下命令
yum -y install gcc
yum -y install gcc-c++
4.如果以前安装过docker 请卸载它们以及相关的依赖项
# 在终端输入以下命令
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
5.安装yum-utils
包
[root@suzhongde suzhongde]# yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.cn99.com
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
6.设置稳定的存储库
[root@suzhongde suzhongde]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://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
7.配置yum源之后更新软件包的索引
[root@suzhongde suzhongde]# yum makecache fast
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.cn99.com
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/primary_db | 73 kB 00:00:05
docker-ce-stable/7/x86_64/upda FAILED
https://download.docker.com/linux/centos/7/x86_64/stable/repodata/65c4f66e2808d328890505c3c2f13bb35a96f457d1c21a6346191c4dc07e6080-updateinfo.xml.gz: [Errno 14] curl#51 - "Unable to communicate securely with peer: requested domain name does not match the server's certificate."
Trying other mirror.
Metadata Cache Created
8.安装 Docker Engine
[root@suzhongde suzhongde]# yum -y install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.5.10-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.5.10-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:20.10.13-3.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.13-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.13-3.el7 will be installed
--> Processing Dependency: docker-scan-plugin(x86-64) for package: 1:docker-ce-cli-20.10.13-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package docker-ce-rootless-extras.x86_64 0:20.10.13-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.13-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.13-3.el7.x86_64
---> Package docker-scan-plugin.x86_64 0:0.17.0-3.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 slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================================================================================
Installing:
containerd.io x86_64 1.5.10-3.1.el7 docker-ce-stable 30 M
docker-ce x86_64 3:20.10.13-3.el7 docker-ce-stable 22 M
docker-ce-cli x86_64 1:20.10.13-3.el7 docker-ce-stable 30 M
Installing for dependencies:
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
docker-ce-rootless-extras x86_64 20.10.13-3.el7 docker-ce-stable 8.1 M
docker-scan-plugin x86_64 0.17.0-3.el7 docker-ce-stable 3.7 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
slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k
Transaction Summary
=================================================================================================================================================================================================================================================
Install 3 Packages (+6 Dependent packages)
Total download size: 95 M
Installed size: 382 M
Downloading packages:
(1/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:05
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.13-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 5.1 MB/s | 21 MB 00:00:14 ETA
Public key for docker-ce-20.10.13-3.el7.x86_64.rpm is not installed
(2/9): docker-ce-20.10.13-3.el7.x86_64.rpm | 22 MB 00:00:08
(3/9): docker-ce-cli-20.10.13-3.el7.x86_64.rpm | 30 MB 00:00:02
(4/9): docker-ce-rootless-extras-20.10.13-3.el7.x86_64.rpm | 8.1 MB 00:00:01
(5/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00
(6/9): docker-scan-plugin-0.17.0-3.el7.x86_64.rpm | 3.7 MB 00:00:00
(7/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:00
(8/9): containerd.io-1.5.10-3.1.el7.x86_64.rpm | 30 MB 00:00:15
(9/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:05
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 5.1 MB/s | 95 MB 00:00:18
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
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : docker-scan-plugin-0.17.0-3.el7.x86_64 1/9
Installing : 1:docker-ce-cli-20.10.13-3.el7.x86_64 2/9
Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 3/9
Installing : containerd.io-1.5.10-3.1.el7.x86_64 4/9
Installing : slirp4netns-0.4.3-4.el7_8.x86_64 5/9
Installing : fuse3-libs-3.6.1-4.el7.x86_64 6/9
Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64 7/9
Installing : 3:docker-ce-20.10.13-3.el7.x86_64 8/9
Installing : docker-ce-rootless-extras-20.10.13-3.el7.x86_64 9/9
Verifying : fuse3-libs-3.6.1-4.el7.x86_64 1/9
Verifying : containerd.io-1.5.10-3.1.el7.x86_64 2/9
Verifying : 1:docker-ce-cli-20.10.13-3.el7.x86_64 3/9
Verifying : fuse-overlayfs-0.7.2-6.el7_8.x86_64 4/9
Verifying : 3:docker-ce-20.10.13-3.el7.x86_64 5/9
Verifying : docker-ce-rootless-extras-20.10.13-3.el7.x86_64 6/9
Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 7/9
Verifying : slirp4netns-0.4.3-4.el7_8.x86_64 8/9
Verifying : docker-scan-plugin-0.17.0-3.el7.x86_64 9/9
Installed:
containerd.io.x86_64 0:1.5.10-3.1.el7 docker-ce.x86_64 3:20.10.13-3.el7 docker-ce-cli.x86_64 1:20.10.13-3.el7
Dependency Installed:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8 docker-ce-rootless-extras.x86_64 0:20.10.13-3.el7 docker-scan-plugin.x86_64 0:0.17.0-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7
slirp4netns.x86_64 0:0.4.3-4.el7_8
Complete!
9.启动 Docker
[root@suzhongde suzhongde]# systemctl start docker
10.查看Docker版本
[root@suzhongde suzhongde]# docker version
Client: Docker Engine - Community
Version: 20.10.13
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 10 14:09:51 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.13
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 906f57f
Built: Thu Mar 10 14:08:16 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.10
GitCommit: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
11.通过拉去hello-world镜像
测试 Docker Engine是否已正确安装。
[root@suzhongde suzhongde]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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/
12.如果执行docker run hello-world报错需要修改docker镜像源:因为docker默认的源为国外官方源可能出现连接超时所以会报错(下面这个就是例子)
[root@suzhongde suzhongde]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
13.我们需要把镜像源修改为国内的这下面随便选一个就行
阿里云
https://pee6w651.mirror.aliyuncs.com
中国科技大学
https://docker.mirrors.ustc.edu.cn
网易
http://hub-mirror.c.163.com
执行vim /etc/docker/daemon.json
[root@suzhongde suzhongde]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}
设置完成后再终端输入systemctl daemon-reload(重载docker配置)
然后再次在终端输入systemctl restart docker(重启docker)
14.测试数据源是否修改成功
在终端输入docker info查看是否配置成功
[root@suzhongde suzhongde]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.0-docker)
scan: Docker Scan (Docker Inc., v0.17.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.13
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
runc version: v1.0.3-0-gf46b6ba
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.777GiB
Name: suzhongde.com
ID: ZC7Z:JSOV:UC4C:EXOU:S2BI:QBSN:RDFX:FXAV:OV6S:IQ4K:ZCES:FXCS
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
# 这里就是我们配置的数据源
Registry Mirrors:
https://alzgoonw.mirror.aliyuncs.com/
Live Restore Enabled: false
做完这里就可以尝试拉去镜像了-在终端输入docker run hello-world拉取镜像
15.查看本地镜像
在终端输入docker images
[root@suzhongde suzhongde]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 5 months ago 13.3kB