1、卸載已安裝的Docker
[root@server ~]# yum list installed | grep docker
[root@server ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
2荐捻、安裝前的準備
?? A)安裝基礎(chǔ)包
[root@server ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
?? B)設(shè)置穩(wěn)定倉庫
[root@server ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
?? 注:阿里倉庫辐棒,下載速度相對要快,也可以使用官網(wǎng)https://download.docker.com/linux/centos/docker-ce.repo
3秕噪、安裝Docker
?? A)安裝containerd.io(版本號>= 1.2.2-3)
[root@server ~]# cd /data/downloads/
[root@server downloads]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
[root@server downloads]# yum -y install containerd.io-1.2.13-3.1.el7.x86_64.rpm
[root@server downloads]# yum list containerd.io
Last metadata expiration check: 0:07:32 ago on Tue 14 Apr 2020 07:32:17 AM CST.
Installed Packages
containerd.io.x86_64 1.2.13-3.1.el7 @@commandline
?? B)安裝Docker-CE
[root@server ~]# yum -y install docker-ce docker-ce-cli
[root@server ~]# yum list docker-ce --showduplicates | sort -r
Last metadata expiration check: 0:12:46 ago on Tue 14 Apr 2020 07:32:17 AM CST.
Installed Packages
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 @docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
Available Packages
4钳降、修改鏡像源
[root@Server ~]# mkdir /etc/docker
[root@server ~]# vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://uoggbpok.mirror.aliyuncs.com",
"https://68rmyzg7.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
5、啟動Docker
[root@server ~]# systemctl daemon-reload
[root@server ~]# systemctl start docker
[root@server ~]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@server ~]# docker version
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:27:04 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:25:42 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
[root@server ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.8
Storage Driver: overlay2
Backing Filesystem: <unknown>
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
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: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-147.8.1.el8_1.x86_64
Operating System: CentOS Linux 8 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.943GiB
Name: Server
ID: FEHB:GM6C:T7KF:ISRU:CJOE:4WIV:PC2Q:BSRF:LDY6:GCRN:VYEL:M3UC
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
6腌巾、測試Docker
[root@server ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
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/
?? 至此遂填,Docker安裝完成,可以開始暢游Docker了澈蝙。
7吓坚、優(yōu)化配置
?? 1)修改Docker默認存儲位置
[root@server ~]# docker info | grep "Docker Root Dir"
WARNING: No blkio weight support
WARNING: No blkio weight_device support
Docker Root Dir: /var/lib/docker
[root@server ~]# mkdir /data/docker
[root@server ~]# vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://uoggbpok.mirror.aliyuncs.com",
"https://68rmyzg7.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
],
"data-root": "/data/docker"
}
[root@server ~]# systemctl restart docker.service
[root@server ~]# docker info | grep "Docker Root Dir"
WARNING: No blkio weight support
WARNING: No blkio weight_device support
Docker Root Dir: /data/docker
?? 2)修改Docker默認Bridge網(wǎng)段
[root@server ~]#
[
{
"Name": "bridge",
"Id": "ae1572de2ae930c25fec7956f4ee0017698d7e2686f753635fadee559d4c2e1b",
"Created": "2021-01-28T15:26:54.464606643+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
[root@server ~]# vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://uoggbpok.mirror.aliyuncs.com",
"https://68rmyzg7.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
],
"data-root": "/data/docker",
"bip":"192.168.12.254/24"
}
[root@server ~]# systemctl restart docker.service
[root@server ~]# docker network inspect bridge
[
{
"Name": "bridge",
"Id": "0566e4383fede4d6e030f3c0b37075faa725610b376782722f80e2e0151935ae",
"Created": "2021-01-28T15:33:28.163155966+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.12.0/24",
"Gateway": "192.168.12.254"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
?? 3)創(chuàng)建Docker自定義網(wǎng)橋
[root@server ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
93d41f979fd4 bridge bridge local
3cf3dbc354ff host host local
0da6c776914c none null local
[root@server ~]# docker network create --subnet=192.168.12.0/24 --gateway=192.168.12.254 static
161109aa22bb47a85bd7c8edb457e90eaa0dcc686ea6b47b91d858d9ff507203
[root@server ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
b3806b8e6e90 bridge bridge local
3cf3dbc354ff host host local
0da6c776914c none null local
161109aa22bb static bridge local
[root@server ~]# docker network inspect static
[
{
"Name": "static",
"Id": "161109aa22bb47a85bd7c8edb457e90eaa0dcc686ea6b47b91d858d9ff507203",
"Created": "2021-01-28T16:09:42.93352796+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "192.168.12.0/24",
"Gateway": "192.168.12.254"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
[root@server ~]# ifconfig
br-161109aa22bb: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.12.254 netmask 255.255.255.0 broadcast 192.168.12.255
ether 02:42:40:96:46:85 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 2066 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:16ff:feee:1a13 prefixlen 64 scopeid 0x20<link>
ether 02:42:16:ee:1a:13 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 2066 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.130 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::f816:3eff:feaa:dfbf prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:aa:df:bf txqueuelen 1000 (Ethernet)
RX packets 92474 bytes 453913931 (432.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 74264 bytes 9172023 (8.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
8、安裝問題
?? 1)如果直接使用yum -y install docker-ce docker-ce-cli containerd.io
命令進行安裝灯荧,會提示如下的錯誤信息:
[root@server ~]# yum -y install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:00:39 ago on Tue 14 Apr 2020 07:32:17 AM CST.
Error:
Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded
- package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
?? 針對此問題礁击,只需要按照文中提到的手動安裝containerd.io
即可,謹記其版本號>= 1.2.2-3。
?? 2)docker命令不能tab鍵自動補全哆窿,需要依賴bash-completion工具链烈。
[root@server ~]# yum install -y bash-completion
[root@server ~]# source /usr/share/bash-completion/bash_completion
[root@server ~]# source /usr/share/bash-completion/completions/docker