警告:切勿在沒有配置 Docker dnf 源的情況下直接使用 dnf 命令安裝 Docker.
Docker CE 支持以下版本的 Fedora 操作系統(tǒng):
舊版本的 Docker 稱為 docker
或者 docker-engine
,使用以下命令卸載舊版本:
$ sudo dnf remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
執(zhí)行以下命令安裝依賴包:
$ sudo dnf -y install dnf-plugins-core
鑒于國內(nèi)網(wǎng)絡問題,強烈建議使用國內(nèi)源,官方源請在注釋中查看。
執(zhí)行下面的命令添加 dnf
軟件源:
$ sudo dnf config-manager \
--add-repo \
https://mirrors.ustc.edu.cn/docker-ce/linux/fedora/docker-ce.repo
$ sudo sed -i 's/download.docker.com/mirrors.ustc.edu.cn\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
# 官方源
# $ sudo dnf config-manager \
# --add-repo \
# https://download.docker.com/linux/fedora/docker-ce.repo
如果需要測試版本的 Docker CE 請使用以下命令:
$ sudo dnf config-manager --set-enabled docker-ce-test
如果需要每日構建版本的 Docker CE 請使用以下命令:
$ sudo dnf config-manager --set-enabled docker-ce-nightly
你也可以禁用測試版本的 Docker CE
$ sudo dnf config-manager --set-disabled docker-ce-test
更新 dnf
軟件源緩存,并安裝 docker-ce
。
$ sudo dnf update
$ sudo dnf install docker-ce
你也可以使用以下命令安裝指定版本的 Docker
$ dnf list docker-ce --showduplicates | sort -r
docker-ce.x86_64 18.06.1.ce-3.fc28 docker-ce-stable
$ sudo dnf -y install docker-ce-18.06.1.ce
由于 Fedora 31 默認啟用了 Cgroupv2,暫時 Docker 與 Cgroupv2 不兼容,請執(zhí)行以下命令切換到 Cgroupv1 并重啟計算機:
$ sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
在測試或開發(fā)環(huán)境中 Docker 官方為了簡化安裝流程,提供了一套便捷的安裝腳本,Debian 系統(tǒng)上可以使用這套腳本安裝,另外可以通過 --mirror
選項使用國內(nèi)源進行安裝:
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
# $ sudo sh get-docker.sh --mirror AzureChinaCloud
執(zhí)行這個命令后,腳本就會自動的將一切準備工作做好,并且把 Docker CE 最新穩(wěn)定(stable)版本安裝在系統(tǒng)中。
$ sudo systemctl enable docker
$ sudo systemctl start docker
默認情況下,docker
命令會使用 Unix socket 與 Docker 引擎通訊。而只有 root
用戶和 docker
組的用戶才可以訪問 Docker 引擎的 Unix socket。出于安全考慮,一般 Linux 系統(tǒng)上不會直接使用 root
用戶。因此,更好地做法是將需要使用 docker
的用戶加入 docker
用戶組。
建立 docker
組:
$ sudo groupadd docker
將當前用戶加入 docker
組:
$ sudo usermod -aG docker $USER
退出當前終端并重新登錄,進行如下測試。
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
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/
若能正常輸出以上信息,則說明安裝成功。