今天我们主要来聊一聊在 Rocky Linux 上安装 Docker CE,相信大部分朋友对 Docker 都有一定的了解,Docker CE做为一款社区开源容器软件,它几乎可以安装在任何主流操作系统上,相信有 CentOS 基因的 Rocky Linux 安装也不是什么难事,让我们一起学习一下吧。
安装Docker CE
注:此安装步骤支持所有 Red Hat 系 Linux 操作系统,所以它适应包括:Red Hat/CentOS/Rocky Linux/Alma Linux/Oracle Linux等操作系统。
# 添加Docker Repo
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
# 更新源
dnf update
# 安装Docker
dnf install -y docker-ce
# 启动Docker服务
sudo systemctl start docker && sudo systemctl status docker
# 设置开机自启动
sudo systemctl enable docker
# 建议添加普通用户至Docker组,并以普通用户运行Docker。
sudo usermod -aG docker $USER
# 生效组用户变更配置
newgrp docker
查看Docker信息
[root@localhost ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
scan: Docker Scan (Docker Inc., v0.21.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.21
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
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 logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661
runc version: v1.1.4-0-g5fd4c4d
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.14.0-162.6.1.el9_1.x86_64
Operating System: Rocky Linux 9.1 (Blue Onyx)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.501GiB
Name: localhost.localdomain
ID: FGNX:GZTC:FQXN:SESU:5TDF:RWIA:EC2L:3T7M:F37V:HHGE:EPZB:KRW5
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
测试部署Docker
# 拉取镜像
[root@localhost ~]# docker pull alpine
# 启动Docker
[root@localhost ~]# docker run -it alpine /bin/sh
/ # ping www.rockylinux.cn
PING www.rockylinux.cn (172.67.209.92): 56 data bytes
64 bytes from 172.67.209.92: seq=0 ttl=53 time=170.018 ms
64 bytes from 172.67.209.92: seq=1 ttl=53 time=170.505 ms
64 bytes from 172.67.209.92: seq=2 ttl=53 time=169.930 ms
64 bytes from 172.67.209.92: seq=3 ttl=53 time=170.345 ms
^C
--- www.rockylinux.cn ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 169.930/170.199/170.505 ms
相关参数配置(daemon.json)
从修改 Docker 文件系统为 ovelay2 驱动,并配置 Docker 下载加速器地址,因为国内很多 Docker 加速器都需要进行认证,中国科学技术大学不需要进行认证,所以这里采用中国科学技术大学的 Docker 加速器。
[root@localhost ~]# mkdir /etc/docker
[root@localhost ~]# cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"], # 一般用于配置国内 DockerHub 镜像加速仓库
"insecure-registries":["https://dockerhub.rockylinux.cn"], # 一般用于配置私有仓库
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"], # Docker远程管理,可以结合portainer WEB管理工具一起使用
"exec-opts": ["native.cgroupdriver=systemd"], # 官方推荐使用systemd,非常不建议使用cgroupfs
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "10"
},
"storage-driver": "overlay2",
"storage-opts":["overlay2.override_kernel_check=true"],
"live-restore": true, # docker daemon进程重启,而容器不重启,一直在线。
"default-shm-size": "128M", # 设置/dev/shm的大小,默认值是64M
"max-concurrent-downloads": 10, # pull镜像的最大并行数,默认为3个
"max-concurrent-uploads": 10, # push镜像的最大并行数,默认为5个
"oom-score-adjust": -1000,
"debug": false # 关闭debug日志
}
EOF
# 重启Docker
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
建议公众号也同步一下这些文章,RockyLinux 公众号已经好久没有更新啦~
好的,我们尽快打通与微信公众号之前的文章同步功能。
docker.service: Failed with result ‘exit-code’.
修改配置文件后缀 —>把/etc/docker/daemon.json文件的.json后缀,修改为.conf后缀
Good @-@