CentOS 8.1 安裝Docker

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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市挚躯,隨后出現(xiàn)的幾起案子强衡,更是在濱河造成了極大的恐慌,老刑警劉巖码荔,帶你破解...
    沈念sama閱讀 206,602評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件漩勤,死亡現(xiàn)場離奇詭異,居然都是意外死亡目胡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,442評論 2 382
  • 文/潘曉璐 我一進店門链快,熙熙樓的掌柜王于貴愁眉苦臉地迎上來誉己,“玉大人,你說我怎么就攤上這事域蜗【匏” “怎么了?”我有些...
    開封第一講書人閱讀 152,878評論 0 344
  • 文/不壞的土叔 我叫張陵霉祸,是天一觀的道長筑累。 經(jīng)常有香客問我,道長丝蹭,這世上最難降的妖魔是什么慢宗? 我笑而不...
    開封第一講書人閱讀 55,306評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮奔穿,結(jié)果婚禮上镜沽,老公的妹妹穿的比我還像新娘。我一直安慰自己贱田,他們只是感情好缅茉,可當(dāng)我...
    茶點故事閱讀 64,330評論 5 373
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著男摧,像睡著了一般蔬墩。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上耗拓,一...
    開封第一講書人閱讀 49,071評論 1 285
  • 那天拇颅,我揣著相機與錄音,去河邊找鬼乔询。 笑死蔬蕊,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播岸夯,決...
    沈念sama閱讀 38,382評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼麻献,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了猜扮?” 一聲冷哼從身側(cè)響起勉吻,我...
    開封第一講書人閱讀 37,006評論 0 259
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎旅赢,沒想到半個月后齿桃,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,512評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡煮盼,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,965評論 2 325
  • 正文 我和宋清朗相戀三年短纵,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片僵控。...
    茶點故事閱讀 38,094評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡香到,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出报破,到底是詐尸還是另有隱情悠就,我是刑警寧澤,帶...
    沈念sama閱讀 33,732評論 4 323
  • 正文 年R本政府宣布充易,位于F島的核電站梗脾,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏盹靴。R本人自食惡果不足惜炸茧,卻給世界環(huán)境...
    茶點故事閱讀 39,283評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望稿静。 院中可真熱鬧宇立,春花似錦、人聲如沸自赔。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,286評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽绍妨。三九已至润脸,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間他去,已是汗流浹背毙驯。 一陣腳步聲響...
    開封第一講書人閱讀 31,512評論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留灾测,地道東北人爆价。 一個月前我還...
    沈念sama閱讀 45,536評論 2 354
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親铭段。 傳聞我的和親對象是個殘疾皇子骤宣,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,828評論 2 345

推薦閱讀更多精彩內(nèi)容