Yum Repository Configuration
Update the package manager to utilize accelerated mirrors. Preserve the existing configuration before modifications:
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
Fetch the updated repository definition:
curl -fsSL -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
Rebuild the package cache:
yum clean all && yum makecache fast
If process lock errors occur, clear the stale PID file:
rm -f /var/run/yum.pid
Docker Engine Setup
Cleanup of Existing Installations
When upgrading or replacing previous Docker versions, purge legacy data:
# Terminate active containers
docker stop $(docker ps -q) 2>/dev/null || true
# Eliminate containers and layer cache
docker rm $(docker ps -aq) 2>/dev/null || true
docker rmi $(docker images -q) 2>/dev/null || true
# Remove packages
yum remove -y docker-ce docker-ce-cli containerd.io docker-common
# Purge residual data
rm -rf /var/lib/docker /var/lib/containerd /etc/docker
Package Installation
Install prerequisite utilities:
yum install -y yum-utils device-mapper-persistent-data lvm2
Register the Docker CE repository using domestic mirrors:
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Deploy the Docker components:
yum makecache fast
yum install -y docker-ce docker-ce-cli containerd.io
Service Configuration
Establish the configuration directory structure:
mkdir -p /etc/docker
Implement registry mirror acceleration to improve pull speeds:
cat > /etc/docker/daemon.json <<'JSON_EOF'
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://docker.1panel.live",
"https://hub.rat.dev"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
JSON_EOF
Initialize the service:
systemctl daemon-reload
systemctl enable --now docker
Validate the deployment:
docker run --rm hello-world
Docker Compose Deployment
Define the target version and binary location:
COMPOSE_RELEASE="v2.24.0"
BINARY_PATH="/usr/local/bin/docker-compose"
Retrieve the compiled binary:
curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_RELEASE}/docker-compose-linux-x86_64" \
-o ${BINARY_PATH}
Apply execution permissions and system-wide linkage:
chmod +x ${BINARY_PATH}
ln -sf ${BINARY_PATH} /usr/bin/docker-compose
Confirm functionality:
docker-compose version