安装Docker-CE
修改repo源
修改为国内阿里源以提高安装速度
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
设置存储库
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装
安装docker-ce时会同步安装containerd.io、docker-ce-cli、docker-buildx-plugin、docker-ce-rootless-extras和docker-compose-plugin。
dnf install -y docker-ce
此命令还会创建一个 docker组,但默认情况下不会向该组添加任何用户。
允许非root用户运行
Docker 守护程序绑定到 Unix 套接字,而不是 TCP 端口。
默认情况下,用户 root拥有 Unix 套接字,Docker守护程序始终以root用户身份运行,其他用户只能使用sudo访问。
如果不想docker在命令前加上sudo,可以创建一个名为docker的Unix组并向其中添加普通用户。
usermod -aG docker anliven
newgrp docker
设置自启动并启动
systemctl --now enable docker
验证安装
下载运行hello-world映像,容器运行时会打印一条确认消息并退出。
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守护进程配置文件
- 修改 Docker 文件系统为 ovelay2 驱动
- 配置 Docker 下载加速器地址(中国科学技术大学不需要进行认证)
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","https://mirror.iscas.ac.cn"],
"insecure-registries":["docker.rockylinux.cn"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "10"
},
"storage-driver": "overlay2",
"live-restore": true,
"default-shm-size": "128M",
"max-concurrent-downloads": 10,
"max-concurrent-uploads": 10,
"debug": false
}
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/
标签:Rockly,node200,CE,64,ce,Docker,root,docker From: https://www.cnblogs.com/anliven/p/18399355