Installing Docker CE on CentOS 7 via YUM Repository Configuration
System Prerequisites Verification
Prior to installation, verify the operating system release to ensure compatibility, as Docker requires a CentOS 7 environment or newer. This can be checked using the following command:
lsb_release -a
Additionally, the system architecture must be 64-bit with a kernel version of at least 3.10. Inspect the current kernel version using:
uname -r
Repository Setup and Dependency Management
Check for any existing Docker installations that might conflict with the new setup:
rpm -qa | grep docker
If legacy Docker versions or遗留 dependencies are present, remove them completely to avoid conflicts:
yum remove docker docker-common docker-selinux docker-engine
Install the necessary utility packages required for the installation process. yum-utils provides the configuration manager, while device-mapper-persistent-data and lvm2 are essential for the devicemapper storage driver:
yum install -y yum-utils device-mapper-persistent-data lvm2
Configure the YUM repository to use the official Docker CE repository. To improve download speeds in regions outside the US, utilizing a mirror repository such as Aliyun is recommended:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Update the package cache to ensure the repository metadata is current:
yum makecache fast
Docker CE Installation Process
Install the Docker Community Edition. To ensure stability in a production environment, it is often advisable to specify a version rather than pulling the latest build:
yum -y install docker-ce-18.06.3.ce
If the installation fails with a mirror error, resolve it by cleaning the metadata and rebuilding the cache:
yum clean all
yum makecache
yum -y update
Service Initialization and Status Check
Initialize the Docker daemon:
systemctl start docker
Verify that the service is running correctly by checking its status:
systemctl status docker
The output should indicate active (running). For further validation, execute the version command to ensure both the client and server components are operational:
docker version
Storage Path and Mirror Accelerator Configuration
By default, Docker stores data in /var/lib/docker. To migrate this to a dedicated directory with more capacity, such as /home/data/docker, create the target directory first:
mkdir -p /home/data/docker
Configure the Docker daemon by creating or editing the /etc/docker/daemon.json file. This configuration sets the new data directory and applies an image accelerator for faster pulls:
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"data-root": "/home/data/docker"
}
Users operating in China should replace the mirror URL with a specific address from the Aliyun Container Service console. Navigate to the "Image Accelerator" section within the console to obtain the unique endpoint assigned to your account.
Apply the configuration changes by reloading the systemd daemon and restarting the Docker service. It is also standard practice to enable the service to start on boot:
systemctl daemon-reload && systemctl enable docker && systemctl restart docker
Post-Installation Verification
Confirm that the storage path modification was successful by inspecting the Docker information:
docker info
Locate the Docker Root Dir field in the output to ensure it reflects the new path. Finally, confirm the installed package details:
yum list installed | grep docker