安装Docker

本文最后更新于 2024年12月2日 晚上

Ubuntu安装Docker

准备工作

卸载旧版本

1
2
apt-get remove docker docker-engine docker.io containerd runc
apt-get autoremove docker-ce

删除 /etc/apt/sources.list.d 目录下的 docker.list 文件

1
rm /etc/apt/sources.list.d/docker.list

脚本安装

下载docker安装脚本

1
curl -fsSL get.docker.com -o /usr/local/docker/get-docker.sh

阿里云安装docker

1
sh get-docker.sh --mirror Aliyun

微软云安装

1
sh get-docker.sh --mirror AzureChinaCloud

APT安装

更新数据源

1
apt-get update

安装所需依赖

1
apt-get -y install apt-transport-https ca-certificates curl software-properties-common

安装 GPG 证书

1
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

新增数据源

1
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

更新并安装 Docker CE

1
apt-get update && apt-get install -y docker-ce

命令安装

1
apt-get install docker.io

验证安装是否成功

使用docker version查看版本信息,输出如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Client:
Version: 18.09.6
API version: 1.39
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 02:35:57 2019
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 18.09.6
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 01:59:36 2019
OS/Arch: linux/amd64
Experimental: false

配置镜像加速器

通过修改 daemon 配置文件 vi /etc/docker/daemon.json 来使用加速器,内容如下:

1
2
3
4
5
6
7
8
9
10
11
{
"registry-mirrors": [
"https://k1wk9ynb.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
],
"insecure-registries":[
"192.168.0.111:5000"
]
}

应用修改后的配置

1
systemctl daemon-reload

重启docker

1
systemctl restart docker

验证加速器 docker info , 输出如下

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
Containers: 38
Running: 18
Paused: 0
Stopped: 20
Images: 10
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.15.0-51-generic
Operating System: Ubuntu 18.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.924GiB
Name: kubernetes-master
ID: PJ4H:7AF2:P5UT:6FMR:W4DI:SSWR:IQQR:J6QO:ARES:BOAC:ZVMO:SV2Y
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
## 这里是你配置的镜像加速器
Registry Mirrors:
https://xxxxxxxx.mirror.aliyuncs.com/
Live Restore Enabled: false
Product License: Community Engine

WARNING: No swap limit support

安装Docker
https://www.bugfree.top/2021/03/20/docker/安装Docker/
作者
lizhenguo
发布于
2021年3月20日
更新于
2024年12月2日
许可协议