ubuntu安装docker

Ubuntu安装docker

一、先更新apt源

1.1 更新系统apt源

此次系统使用的是 Ubuntu Server 20.04 LTS版本

1
root@k8s-master-61:~# apt update

二、安装依赖组件包

2.1 安装docker所需要的依赖组件包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
root@k8s-master-61:~# apt -y install apt-transport-https ca-certificates curl software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libcurl4 python3-software-properties
The following NEW packages will be installed:
apt-transport-https
The following packages will be upgraded:
ca-certificates curl libcurl4 python3-software-properties software-properties-common
5 upgraded, 1 newly installed, 0 to remove and 244 not upgraded.
Need to get 574 kB of archives.
After this operation, 138 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 ca-certificates all 20211016ubuntu0.20.04.1 [141 kB]
Get:2 http://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 apt-transport-https all 2.0.9 [1,704 B]
Get:3 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 curl amd64 7.68.0-1ubuntu2.14 [161 kB]
Get:4 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 libcurl4 amd64 7.68.0-1ubuntu2.14 [235 kB]
Get:5 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 software-properties-common all 0.99.9.8 [10.6 kB]
Get:6 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 python3-software-properties all 0.99.9.8 [24.9 kB]
Fetched 574 kB in 1s (465 kB/s)
Preconfiguring packages ...
(Reading database ... 71222 files and directories currently installed.)
Preparing to unpack .../0-ca-certificates_20211016ubuntu0.20.04.1_all.deb ...
Unpacking ca-certificates (20211016ubuntu0.20.04.1) over (20201027ubuntu0.20.04.1) ...
Selecting previously unselected package apt-transport-https.
Preparing to unpack .../1-apt-transport-https_2.0.9_all.deb ...
Unpacking apt-transport-https (2.0.9) ...
Preparing to unpack .../2-curl_7.68.0-1ubuntu2.14_amd64.deb ...
Unpacking curl (7.68.0-1ubuntu2.14) over (7.68.0-1ubuntu2.4) ...
Preparing to unpack .../3-libcurl4_7.68.0-1ubuntu2.14_amd64.deb ...
Unpacking libcurl4:amd64 (7.68.0-1ubuntu2.14) over (7.68.0-1ubuntu2.4) ...
Preparing to unpack .../4-software-properties-common_0.99.9.8_all.deb ...
Unpacking software-properties-common (0.99.9.8) over (0.98.9.3) ...
Preparing to unpack .../5-python3-software-properties_0.99.9.8_all.deb ...
Unpacking python3-software-properties (0.99.9.8) over (0.98.9.3) ...
Setting up apt-transport-https (2.0.9) ...
Setting up ca-certificates (20211016ubuntu0.20.04.1) ...
Updating certificates in /etc/ssl/certs...
rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL
8 added, 22 removed; done.
Setting up python3-software-properties (0.99.9.8) ...
Setting up libcurl4:amd64 (7.68.0-1ubuntu2.14) ...
Setting up curl (7.68.0-1ubuntu2.14) ...
Setting up software-properties-common (0.99.9.8) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for dbus (1.12.16-2ubuntu2.1) ...
Processing triggers for ca-certificates (20211016ubuntu0.20.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

三、安装验证证书

3.1 安装gpg证书

这里采用的是华为云镜像站的源,之前测过 阿里云和清华源的话 安装速度不太理想

1
2
root@k8s-master-61:~# curl -fsSL http:///repo.huaweicloud.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
OK

3.2 写入软件源信息

1
2
3
4
5
6
7
8
9
10
root@k8s-master-61:~# add-apt-repository "deb [arch=amd64] http://repo.huaweicloud.com/docker-ce/linux/ubuntu/ $(lsb_release -cs) stable"
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease
Get:3 http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal InRelease [57.7 kB]
Hit:4 http://mirrors.aliyun.com/ubuntu focal-updates InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu focal-proposed InRelease
Hit:6 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
Get:7 http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages [21.3 kB]
Fetched 79.0 kB in 1s (139 kB/s)
Reading package lists... Done

四、安装docker

4.1 需要再次更新apt源

由于新添加了docker的信息后,apt的源需要再次更新下才行

1
2
3
4
5
6
7
8
9
10
11
root@k8s-master-61:~# apt update 
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu focal-proposed InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
Hit:6 http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
244 packages can be upgraded. Run 'apt list --upgradable' to see them.

4.2 查找docker-CE的版本

你可以通过以下命令去查找你所想安装的docker版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
root@k8s-master-61:~# apt-cache madison docker-ce
docker-ce | 5:20.10.21~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.20~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.19~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.18~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.17~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.16~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.15~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.14~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.13~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.12~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.11~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.10~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.9~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.8~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.7~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.6~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.5~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.4~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.3~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.2~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.1~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.0~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.15~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.14~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.13~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.12~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.11~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.10~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.9~3-0~ubuntu-focal | http://repo.huaweicloud.com/docker-ce/linux/ubuntu focal/stable amd64 Packages

4.3 安装指定版本的docker

通过上述操作找到相对应的版本号后接下来进行安装

1
2
3
4
5
6
7
8
9
10
11
12
13
root@k8s-master-61:~# apt -y install docker-ce=5:20.10.21~3-0~ubuntu-focal
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
containerd.io docker-ce-cli docker-ce-rootless-extras docker-scan-plugin libseccomp2 pigz slirp4netns
Suggested packages:
......
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for systemd (245.4-4ubuntu3.4) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

五、安装完验证

5.1 查看docker信息

安装好后它会自动把docker服务启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
root@k8s-master-61:~# docker info 
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
scan: Docker Scan (Docker Inc., v0.21.0)

Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.21
Storage Driver: overlay2
Backing Filesystem: extfs
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: a05d175400b1145e5e6a735a6710579d181e7fb0
runc version: v1.1.4-0-g5fd4c4d
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-65-generic
Operating System: Ubuntu 20.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.816GiB
Name: k8s-master-61
ID: G3LY:KHMV:LGCN:Z4EB:5EOW:7LJP:RFOE:MQBR:YVYZ:S7EN:KS7U:3HZX
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
Live Restore Enabled: false

WARNING: No swap limit support

ubuntu安装docker
https://www.dklwj.com/2022/12/Ubuntu-install-docker.html
作者
阿伟
发布于
2022年12月17日
许可协议