Confirm the RHEL version and repos; default repos need an active subscription
cat /etc/redhat-release
dnf repolistOne-click Docker install script for RHEL 8 / 9: checks subscription status, removes conflicting podman/runc, configures the Aliyun Docker CE repo and installs docker-ce with buildx and the compose plugin, plus SELinux, firewalld and uninstall notes.
Confirm the RHEL version and repos; default repos need an active subscription
cat /etc/redhat-release
dnf repolistCheck subscription status, then register and auto-attach if needed
sudo subscription-manager status
sudo subscription-manager register --auto-attachRHEL ships podman and runc; runc conflicts with containerd.io, so remove it first
sudo dnf remove -y podman buildah runcProvides dnf config-manager for adding third-party repos
sudo dnf install -y dnf-plugins-coreSave as install-docker-rhel.sh and run it as root to finish the install
#!/bin/bash
set -euo pipefail
echo "当前系统: $(cat /etc/redhat-release)"
# 订阅检查,未注册时给出提示而不中断
if command -v subscription-manager >/dev/null 2>&1; then
subscription-manager status >/dev/null 2>&1 || echo "警告: 订阅未注册,请先执行 subscription-manager register"
fi
# 移除与 containerd.io 冲突的包
sudo dnf remove -y podman buildah runc || true
sudo dnf install -y dnf-plugins-core
# 添加阿里云 Docker CE 仓库
sudo dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/rhel/docker-ce.repo
# 安装 Docker 引擎与插件
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# 开机自启并验证
sudo systemctl enable --now docker
docker --version
docker compose versionIf the repo returns 404, use the centos path or the official download.docker.com repo.
Make it executable and run as root to avoid repeated sudo prompts
chmod +x install-docker-rhel.sh
sudo bash install-docker-rhel.shAdd the Docker CE repo and confirm the repo file exists
sudo dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/rhel/docker-ce.repo
ls /etc/yum.repos.d/ | grep dockerRefresh metadata and list available versions from the Docker repo
sudo dnf makecache
dnf list docker-ce --showduplicates | headInstall the engine, CLI, containerd, buildx and the compose plugin
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginUse --allowerasing to let dnf remove conflicting runc or podman packages
sudo dnf install -y --allowerasing docker-ceVerify all three work; compose is a plugin, not the legacy binary
docker --version
docker compose version
docker buildx versionEnable at boot, start now and confirm the active state
sudo systemctl enable --now docker
systemctl status docker --no-pagerJoin the docker group to skip sudo; newgrp applies it immediately
sudo usermod -aG docker "$USER"
newgrp dockerThe docker group is effectively root-level access; grant it carefully.
Set a registry mirror from your cloud console instead of public links
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<'EOF'
{
"registry-mirrors": ["<你的镜像加速地址>"]
}
EOFReload and restart; the mirror should appear in docker info output
sudo systemctl daemon-reload
sudo systemctl restart docker
docker info | grep -A2 "Registry Mirrors"Keep mirror and log settings in one JSON; separate writes overwrite each other
sudo tee /etc/docker/daemon.json <<'EOF'
{
"registry-mirrors": ["<你的镜像加速地址>"],
"log-driver": "json-file",
"log-opts": { "max-size": "100m", "max-file": "3" }
}
EOFRun the official test image to confirm the engine and image pulling
docker run --rm hello-worldCheck these logs on failure; malformed daemon.json is the usual cause
systemctl status docker --no-pager
journalctl -u docker -n 50 --no-pagerUnder Enforcing SELinux, mount with :z or :Z or the container cannot read the path
getenforce
docker run --rm -v /data/html:/usr/share/nginx/html:z nginx:1.25Docker publishes ports outside firewalld, so open them explicitly for external access
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reloadRHEL 8/9 default to cgroup v2 with overlay2; check kernel args if v1 is expected
docker info | grep -iE "cgroup|storage driver"Remove Docker packages while keeping data in /var/lib/docker
sudo dnf remove -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginDelete all images, containers and volumes with no recovery
sudo rm -rf /var/lib/docker /var/lib/containerdRemove the Docker repo so later installs do not hit a stale source
sudo rm -f /etc/yum.repos.d/docker-ce.repo
sudo dnf makecacheThis website uses cookies to ensure you get the best experience on our website. Privacy Policy.