Docker - 在Rocky Linux 9.4 上安裝Docker-CE
安裝Docker-CE
修改repo源
修改為國內(nèi)阿里源以提高安裝速度
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/rocky*.repo
設(shè)置存儲(chǔ)庫
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安裝
安裝docker-ce時(shí)會(huì)同步安裝containerd.io、docker-ce-cli、docker-buildx-plugin、docker-ce-rootless-extras和docker-compose-plugin。
dnf install -y docker-ce
此命令還會(huì)創(chuàng)建一個(gè) docker組,但默認(rèn)情況下不會(huì)向該組添加任何用戶。
允許非root用戶運(yùn)行
Docker 守護(hù)程序綁定到 Unix 套接字,而不是 TCP 端口。
默認(rèn)情況下,用戶 root擁有 Unix 套接字,Docker守護(hù)程序始終以root用戶身份運(yùn)行,其他用戶只能使用sudo訪問。
如果不想docker在命令前加上sudo,可以創(chuàng)建一個(gè)名為docker的Unix組并向其中添加普通用戶。
usermod -aG docker anliven
newgrp docker
設(shè)置自啟動(dòng)并啟動(dòng)
systemctl --now enable docker
驗(yàn)證安裝
下載運(yùn)行hello-world映像,容器運(yùn)行時(shí)會(huì)打印一條確認(rèn)消息并退出。
docker run hello-world
安裝過程示例
[root@node200 ~]# uname -a
Linux node200 5.14.0-427.33.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 28 17:34:59 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
[root@node200 ~]#
[root@node200 ~]# cat /etc/system-release
Rocky Linux release 9.4 (Blue Onyx)
[root@node200 ~]#
[root@node200 ~]# dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
[root@node200 ~]#
[root@node200 ~]# dnf install -y docker-ce
Rocky Linux 9 - BaseOS 1.8 MB/s | 2.3 MB 00:01
Rocky Linux 9 - AppStream 4.4 MB/s | 8.0 MB 00:01
Rocky Linux 9 - Extras 20 kB/s | 15 kB 00:00
Dependencies resolved.
=============================================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================================
Installing:
docker-ce x86_64 3:27.2.0-1.el9 docker-ce-stable 27 M
Installing dependencies:
containerd.io x86_64 1.7.21-3.1.el9 docker-ce-stable 43 M
docker-ce-cli x86_64 1:27.2.0-1.el9 docker-ce-stable 7.9 M
Installing weak dependencies:
docker-buildx-plugin x86_64 0.16.2-1.el9 docker-ce-stable 14 M
docker-ce-rootless-extras x86_64 27.2.0-1.el9 docker-ce-stable 4.0 M
docker-compose-plugin x86_64 2.29.2-1.el9 docker-ce-stable 13 M
Transaction Summary
=============================================================================================================================================
Install 6 Packages
......
......
......
Installed:
containerd.io-1.7.21-3.1.el9.x86_64 docker-buildx-plugin-0.16.2-1.el9.x86_64 docker-ce-3:27.2.0-1.el9.x86_64
docker-ce-cli-1:27.2.0-1.el9.x86_64 docker-ce-rootless-extras-27.2.0-1.el9.x86_64 docker-compose-plugin-2.29.2-1.el9.x86_64
Complete!
[root@node200 ~]#
[root@node200 ~]# usermod -aG docker anliven
[root@node200 ~]# newgrp docker
[root@node200 ~]#
[root@node200 ~]# systemctl --now enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@node200 ~]#
[root@node200 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75
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/
[root@node200 ~]#
[root@node200 ~]# docker version
Client: Docker Engine - Community
Version: 27.2.0
API version: 1.47
Go version: go1.21.13
Git commit: 3ab4256
Built: Tue Aug 27 14:17:06 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 27.2.0
API version: 1.47 (minimum version 1.24)
Go version: go1.21.13
Git commit: 3ab5c7d
Built: Tue Aug 27 14:15:14 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.21
GitCommit: 472731909fa34bd7bc9c087e4c27943f9835f111
runc:
Version: 1.1.13
GitCommit: v1.1.13-0-g58aa920
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@node200 ~]#
[root@node200 ~]# docker info
Client: Docker Engine - Community
Version: 27.2.0
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.16.2
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.29.2
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 27.2.0
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111
runc version: v1.1.13-0-g58aa920
init version: de40ad0
Security Options:
seccomp
Profile: builtin
cgroupns
Kernel Version: 5.14.0-427.33.1.el9_4.x86_64
Operating System: Rocky Linux 9.4 (Blue Onyx)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.506GiB
Name: node200
ID: 0ba20da2-13b0-4424-a09e-5fba22a975c3
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
[root@node200 ~]#
[root@node200 ~]# docker compose version
Docker Compose version v2.29.2
[root@node200 ~]#
[root@node200 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d2c94e258dcb 16 months ago 13.3kB
[root@node200 ~]#
[root@node200 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c9ba6bc04b1 hello-world "/hello" About a minute ago Exited (0) About a minute ago unruffled_driscoll
[root@node200 ~]#
配置daemon.json
- daemon.json是Docker守護(hù)進(jìn)程配置文件
- 配置 Docker 下載加速器地址
- 根據(jù)需要配置相關(guān)參數(shù)
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://dockerpull.com"]
}
EOF
systemctl daemon-reload
參考信息
- https://www.rockylinux.cn/notes/zai-rocky-linux-9-1-shang-an-zhuang-docker-ce.html
- https://docs.rockylinux.org/gemstones/containers/docker/
- https://docs.docker.com/engine/install/centos/
行動(dòng)是絕望的解藥!
歡迎轉(zhuǎn)載和引用,但請(qǐng)?jiān)诿黠@處保留原文鏈接和原作者信息!
本博客內(nèi)容多為個(gè)人工作與學(xué)習(xí)的記錄,少數(shù)內(nèi)容來自于網(wǎng)絡(luò)并略有修改,已盡力標(biāo)明原文鏈接和轉(zhuǎn)載說明。如有冒犯,即刻刪除!
以所舍,求所得,有所獲,方所成。

浙公網(wǎng)安備 33010602011771號(hào)