如何在 CentOS 8 下安裝 Docker Engine
CentOS 8 都已經到版本 8.2.2004 了,Docker 官方還是預設只提供 CentOS 7 的安裝包。 這是怎麼回事呢?
網上搜了一下,說是因為 Red Hat 自己推出了 buildah 和 podman 準備替代 Docker。
雖說兼容性不錯,但是你非要在 CentOS 8 下安裝 Docker 能不能辦到呢?
辦法還是有的,只是需要手動來操作。 稍微花點時間,按照本文操作步驟來就可以了。
本文將講解如何在 CentOS 8 下安裝 Docker Engine 以及 docker-compose。
2020 年 11 月 8 日更新日誌:
寫作本文時,Docker 尚未正式發佈在 CentOS 8 下的 rpm 安裝包。
2020 年 9 月 17 日,Docker 已經正式發佈 CentOS 8 下的 rpm 安裝包,因此有更簡單的方式來安裝 Docker Engine。
使用 root 使用者執行以下命令:
wget -qO- get.docker.com | bash
安裝完成後的版本號:
Client: Docker Engine - Community Version: 19.03. 13 API version: 1.40 Go version: go1. 13.15 Git commit: 4484c46d9d Built: Wed Sep 16 17:02:36 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03. 13 API version: 1.40 (minimum version 1.12) Go version: go1. 13.15 Git commit: 4484c46d9d Built: Wed Sep 16 17:01:11 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.3. 7 GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175 runc: Version: 1.0. 0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18. 0 GitCommit: fec3683
至於 docker-compose 的安裝方法,可以繼續參考本文下面第 6 步的方法。
———-以下為原文的分界線———-
在寫本文時,Docker 最新版本號是 19.03.12。
$ docker version Client: Docker Engine - Community Version: 19.03. 12 API version: 1.40 Go version: go1. 13.10 Git commit: 48a66213fe Built: Mon Jun 22 15:46:54 2020 OS/Arch: linux/amd64 Experimental: true Server: Docker Engine - Community Engine: Version: 19.03. 12 API version: 1.40 (minimum version 1.12) Go version: go1. 13.10 Git commit: 48a66213fe Built: Mon Jun 22 15:45:28 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
1. 安裝 docker-ce.repo
CentOS 8 下預設已經是 dnf 命令來進行包管理。
第一步就是安裝 Docker 官方的 repo,執行命令如下:
$ dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
2. 顯示可用版本
$ dnf list docker-ce --showduplicates
返回一覽如下。
Available Packages docker-ce. x86_64 17.03. 0.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. 2.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.06. 0.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. 2.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.09. 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.12. 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 18.03. 1.ce-1.el7.centos docker-ce-stable docker-ce. x86_64 18.06. 0.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. 2.ce-3.el7 docker-ce-stable docker-ce. x86_64 18.06. 3.ce-3.el7 docker-ce-stable docker-ce. x86_64 3:18.09. 0-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. 2-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. 4-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. 6-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. 8-3.el7 docker-ce-stable docker-ce. x86_64 3:18.09. 9-3.el7 docker-ce-stable docker-ce. x86_64 3:19.03. 0-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. 2-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. 4-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. 6-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. 8-3.el7 docker-ce-stable docker-ce. x86_64 3:19.03. 9-3.el7 docker-ce-stable docker-ce. x86_64 3:19.03. 10-3.el7 docker-ce-stable docker-ce. x86_64 3:19.03. 11-3.el7 docker-ce-stable docker-ce. x86_64 3:19.03. 12-3.el7 docker-ce-stable
可以看到,截至目前,最新版已經到了 19.03.12
3. 事先安裝依賴
要想安裝docker-ce 必須事先要安裝好依賴 containerd.io,這裡就是和 CentOS 7 下自動安裝的最大區別。 點擊這裡,查看最新版的 containerd.io。 適當地替換下面命令里的下載連結。
執行如下命令:
$ dnf install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm
4. 安裝 Docker
執行如下命令,注意其中有個--nobest 選項:
$ dnf install -y --nobest docker-ce
5. 啟動 Docker
上一步正確安裝以後,接下來就要啟動 Docker,並設置開機自啟動。
啟動 Docker 命令:
$ systemctl start docker
檢視 Docker 狀態:
$ systemctl status docker
設定開機自啟動 Docker 命令:
$ systemctl enable docker
檢視 Docker 版本資訊:
$ docker version
6. 安裝 docker-compose
利用pip3 來安裝 docker-compose 最為簡單。
事先安裝好 pip3 是必要的,如果本機沒有安裝,執行如下命令安裝 pip3。
$ dnf install -y python3-pip
檢視 pip3 版本資訊:
$ pip3 --version
返回值:
pip 9.0. 3 from /usr/lib/python3.6/site-packages (python 3.6)
安裝 docker-compose 命令
$ pip3 install docker-compose
查看 docker-compose 版本資訊:
$ docker-compose --version
返回值:
docker-compose version 1.26.2,build unknown
Hits: 218