
jimlu
V1
2023/04/16阅读:56主题:默认主题
CentOS7.9安装docker
1、将系统包更新到最新
1、配置epel源
[root@jintest ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
[root@jintest ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
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 | 249 kB 00:00:00
(3/4): base/7/x86_64/primary_db | 6.1 MB 00:00:01
(4/4): updates/7/x86_64/primary_db | 20 MB 00:00:04
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 515
updates/7/x86_64
2、更新系统安装包到最新
-
yum update 升级系统安装包
-
升级完成后关机做快照,然后开机
2、安装docker
1、 获取docker镜像源
[root@jintest ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
--2023-04-14 23:29:12-- https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 180.213.251.233, 36.103.213.209, 36.103.213.208, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|180.213.251.233|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2081 (2.0K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/docker-ce.repo’
100%[===============================================================>] 2,081 --.-K/s in 0s
2023-04-14 23:29:12 (175 MB/s) - ‘/etc/yum.repos.d/docker-ce.repo’ saved [2081/2081]
[root@jintest ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/7/x86_64/primary_db | 102 kB 00:00:00
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
docker-ce-stable/7/x86_64 Docker CE Stable - x86_64 223
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 515
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 4,886
repolist: 15,696
2、安装docker-ce
[root@jintest ~]# yum install -y docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:23.0.3-1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-23.0.3-1.el7.x86_64
--> Processing Dependency: containerd.io >= 1.6.4 for package: 3:docker-ce-23.0.3-1.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-23.0.3-1.el7.x86_64
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-23.0.3-1.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package containerd.io.x86_64 0:1.6.20-3.1.el7 will be installed
---> Package docker-ce-cli.x86_64 1:23.0.3-1.el7 will be installed
--> Processing Dependency: docker-buildx-plugin for package: 1:docker-ce-cli-23.0.3-1.el7.x86_64
--> Processing Dependency: docker-compose-plugin for package: 1:docker-ce-cli-23.0.3-1.el7.x86_64
---> Package docker-ce-rootless-extras.x86_64 0:23.0.3-1.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-23.0.3-1.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-23.0.3-1.el7.x86_64
--> Running transaction check
---> Package docker-buildx-plugin.x86_64 0:0.10.4-1.el7 will be installed
---> Package docker-compose-plugin.x86_64 0:2.17.2-1.el7 will be installed
---> 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:
docker-ce x86_64 3:23.0.3-1.el7 docker-ce-stable 23 M
Installing for dependencies:
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
containerd.io x86_64 1.6.20-3.1.el7 docker-ce-stable 34 M
docker-buildx-plugin x86_64 0.10.4-1.el7 docker-ce-stable 12 M
docker-ce-cli x86_64 1:23.0.3-1.el7 docker-ce-stable 13 M
docker-ce-rootless-extras x86_64 23.0.3-1.el7 docker-ce-stable 8.8 M
docker-compose-plugin x86_64 2.17.2-1.el7 docker-ce-stable 12 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 1 Package (+9 Dependent packages)
Total download size: 103 M
Installed size: 366 M
Downloading packages:
(1/10): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm is not installed
(2/10): docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm | 12 MB 00:00:06
(3/10): containerd.io-1.6.20-3.1.el7.x86_64.rpm | 34 MB 00:00:15
(4/10): docker-ce-23.0.3-1.el7.x86_64.rpm | 23 MB 00:00:09
(5/10): docker-ce-rootless-extras-23.0.3-1.el7.x86_64.rpm | 8.8 MB 00:00:03
(6/10): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00
(7/10): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:00
(8/10): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:00
(9/10): docker-ce-cli-23.0.3-1.el7.x86_64.rpm | 13 MB 00:00:05
(10/10): docker-compose-plugin-2.17.2-1.el7.x86_64.rpm | 12 MB 00:00:04
---------------------------------------------------------------------------------------------------------
Total 4.4 MB/s | 103 MB 00:00:23
Retrieving key from https://mirrors.aliyun.com/docker-ce/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://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 1/10
setsebool: SELinux is disabled.
Installing : containerd.io-1.6.20-3.1.el7.x86_64 2/10
Installing : docker-compose-plugin-2.17.2-1.el7.x86_64 3/10
Installing : slirp4netns-0.4.3-4.el7_8.x86_64 4/10
Installing : docker-buildx-plugin-0.10.4-1.el7.x86_64 5/10
Installing : 1:docker-ce-cli-23.0.3-1.el7.x86_64 6/10
Installing : fuse3-libs-3.6.1-4.el7.x86_64 7/10
Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64 8/10
Installing : 3:docker-ce-23.0.3-1.el7.x86_64 9/10
Installing : docker-ce-rootless-extras-23.0.3-1.el7.x86_64 10/10
Verifying : docker-ce-rootless-extras-23.0.3-1.el7.x86_64 1/10
Verifying : fuse3-libs-3.6.1-4.el7.x86_64 2/10
Verifying : 1:docker-ce-cli-23.0.3-1.el7.x86_64 3/10
Verifying : fuse-overlayfs-0.7.2-6.el7_8.x86_64 4/10
Verifying : docker-buildx-plugin-0.10.4-1.el7.x86_64 5/10
Verifying : 3:docker-ce-23.0.3-1.el7.x86_64 6/10
Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 7/10
Verifying : containerd.io-1.6.20-3.1.el7.x86_64 8/10
Verifying : slirp4netns-0.4.3-4.el7_8.x86_64 9/10
Verifying : docker-compose-plugin-2.17.2-1.el7.x86_64 10/10
Installed:
docker-ce.x86_64 3:23.0.3-1.el7
Dependency Installed:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.6.20-3.1.el7
docker-buildx-plugin.x86_64 0:0.10.4-1.el7 docker-ce-cli.x86_64 1:23.0.3-1.el7
docker-ce-rootless-extras.x86_64 0:23.0.3-1.el7 docker-compose-plugin.x86_64 0:2.17.2-1.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!
3、启动docker
-
systemctl start docker #启动docker -
docker version #查看docker版本
[root@jintest ~]# systemctl start docker
[root@jintest ~]# docker version
Client: Docker Engine - Community
Version: 23.0.3
API version: 1.42
Go version: go1.19.7
Git commit: 3e7cbfd
Built: Tue Apr 4 22:04:18 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 23.0.3
API version: 1.42 (minimum version 1.12)
Go version: go1.19.7
Git commit: 59118bf
Built: Tue Apr 4 22:02:01 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.20
GitCommit: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
runc:
Version: 1.1.5
GitCommit: v1.1.5-0-gf19387a
docker-init:
Version: 0.19.0
GitCommit: de40ad0
注:离线安装
离线安装需要下载至少如下4个rpm包,传到服务器上,再去安装,安装过程中可能还需要解决依赖
docker -ce
containerd.io
docker-ce-cli
container-selinux
3、配置docker镜像加速
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://rqybk619.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
4、运行一个docker镜像
[root@jintest ~]# 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/
作者介绍

jimlu
V1