Docker installation and configuration¶
Docker is a platform that allows developers to package applications and their dependencies into lightweight, portable containers, which can then be published to any popular Linux machine or host operating system^[400-devops-06-kubernetes-k8s-paas-01docker.md].
The installation process involves setting up the necessary repositories, installing the Docker Engine, and configuring the daemon to optimize performance and access^[400-devops-06-kubernetes-k8s-paas-01docker.md].
Prerequisites¶
Before installing Docker, ensure that your system meets the necessary requirements^[400-devops-06-kubernetes-k8s-paas-01docker.md]:
- OS: CentOS 7.6 (or similar Linux distributions).
- Kernel: The kernel version must be 3.8 or higher.
- Hardware: Minimum of 1 CPU core and 2GB of memory (1C2G).
- SELinux: Should be disabled.
- Firewall:
firewalldshould be stopped.
Installation Steps¶
1. Verify System Information¶
Check the kernel version and OS release to ensure compatibility^[400-devops-06-kubernetes-k8s-paas-01docker.md].
uname -a
cat /etc/redhat-release
2. Configure the Repository¶
Install the required utilities and add the Docker CE repository from Aliyun (a recommended mirror for Chinese users)^[400-devops-06-kubernetes-k8s-paas-01docker.md].
# Install necessary utilities
yum install -y yum-utils
# Add Docker repository
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3. Install Docker CE¶
Install Docker Community Edition using yum^[400-devops-06-kubernetes-k8s-paas-01docker.md].
yum install -y docker-ce
Configuration¶
To ensure Docker runs efficiently, it is recommended to modify the daemon configuration file located at /etc/docker/daemon.json^[400-devops-06-kubernetes-k8s-paas-01docker.md].
Key Configuration Options¶
The following is a recommended configuration structure^[400-devops-06-kubernetes-k8s-paas-01docker.md]:
- graph: Specifies the working directory for Docker (e.g.,
/data/docker). - storage-driver: Sets the storage driver, typically
overlay2. - registry-mirrors: Configures image acceleration mirrors (e.g., Aliyun mirrors).
- insecure-registries: Defines private registries that do not use HTTPS.
- bip: Sets the bridge IP address for the Docker network (e.g.,
172.7.5.1/24). - exec-opts: Sets the cgroup driver to
systemdfor better integration with system services. - live-restore: Ensures containers remain running even if the Docker daemon crashes (if set to
true).
Example daemon.json¶
{
"graph": "/data/docker",
"storage-driver": "overlay2",
"insecure-registries": ["registry.access.redhat.com","[Quay.io](<./quayio.md>)"],
"registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
"bip": "172.7.5.1/24",
"exec-opts": ["native.cgroupdriver=systemd"],
"live-restore": true
}
Applying Changes¶
After creating or modifying the configuration file, restart the Docker service to apply the settings^[400-devops-06-kubernetes-k8s-paas-01docker.md].
# Enable Docker to start on boot
systemctl enable docker
# Start the Docker service
systemctl start docker
# Restart to apply configuration changes
systemctl restart docker
# Verify installation and configuration
docker info
Verification¶
You can verify that Docker is installed and running correctly by executing the test command^[600-developer__docker__docker.md]:
docker run hello-world
If successful, this command downloads a test image and prints a welcome message, confirming that the installation is working as expected^[600-developer__docker__docker.md].
Related Concepts¶
Sources¶
- 400-devops-06-kubernetes-k8s-paas-01docker.md
- 600-developer__docker__docker.md