Prerequisites
Supported CentOS Versions
Docker is compatible with the following CentOS releases:
- CentOS 7 (64-bit)
- CentOS 6.5 (64-bit) or later versions
System Requirements
Docker requires specific kernel versions depending on your CentOS version:
- CentOS 7: 64-bit system with kernel version 3.10 or higher
- CentOS 6.5 or later: 64-bit system with kernel version 2.6.32-431 or higher
Docker Architecture Overview
1. Images
A Docker image serves as a read-only template. Images are used to create Docker containers, and a single image can generate multiple containers. Think of images as blueprints that define what the container environment will look like.
2. Containers
Containers are isolated runtime instances created from images. They can be started, stopped, paused, and deleted. Each container operates independently, providing a secure execution environment.
A container can be conceptualized as a lightweight Linux environment (including root user access, process space, user space, and network configuration) along with the applications running within it.
Containers and images share identical layer structures, with the key difference being that the topmost layer of a container is read-write capable.
3. Repositories
A repository serves as a centralized storage location for image files. It's important to distinguish between repositories and registry servers:
- Registry Server: Hosts multiple repositories
- Repository: Contains multiple images with different tags
Repositories come in two forms: public and private. The largest public repository is Docker Hub (https://hub.docker.com/), which hosts an extensive collection of images. Other public options include Alibaba Cloud Container Registry and NetEase Cloud.
4. Conceptual Summary
Understanding the relationship between these componetns is essential:
Docker functions as a container runtime and management engine. Applications and their dependencies are packaged into a deployable runtime environment, which is represented as an image file. Containers are instantiated from these image files. A single image can generate multiple concurrent container instances, each operating independently.
Installation Instructions
Installing Docker on CentOS 6.8
- Install the EPEL repository:
yum install -y epel-release - Install Docker:
yum install -y docker-io - Configuration file location:
/etc/sysconfig/docker - Start the Docker service:
service docker start - Verify the installation:
docker version
Installing Docker on CentOS 7
Official documentation: https://docs.docker.com/engine/install/centos/
- Verify your CentOS version:
cat /etc/redhat-releaseEnsure you have CentOS 7 or later. - Install GCC and related dependencies (requires internet connectivity):
yum -y install gcc gcc-c++ - Uninstall any existing Docker versions:
yum -y remove docker docker-common docker-selinux docker-engine - Install required packages:
yum install -y yum-utils device-mapper-persistent-data lvm2 - Configure the stable Docker repository:
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo - Update the package index:
yum makecache fast - Install Docker Engine:
yum -y install docker-ce - Start the Docker service:
systemctl start docker - Verify the installation:
docker version - Run a test container:
docker run hello-world - Configure image registry mirrors:
mkdir -p /etc/dockervim /etc/docker/daemon.json
For NetEase Mirror:
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
For Alibaba Cloud Mirror:
{
"registry-mirrors": ["https://{your-code}.mirror.aliyuncs.com"]
}
Reload and restart Docker:
systemctl daemon-reloadsystemctl restart docker1. Uninstall Docker: systemctl stop dockeryum -y remove docker-cerm -rf /var/lib/docker
Running Your First Conatiner
Configuring Registry Mirrors
Due to network constraints in certain regions, pulling images from Docker Hub can be extremely slow. Configuring a mirror加速器 significantly improves download speeds.
Alibaba Cloud Mirror Configuration:
- Register an Alibaba Cloud account
- Navigate to the Container Registry service
- Obtain your personal mirror acceleration URL
- Add the configuration to
/etc/docker/daemon.json
NetEase Mirror Configuration:
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
After configuration, restart Docker and verify:
systemctl restart dockerdocker info | grep "Registry Mirrors"#### Testing with hello-world
Run the test container:
docker run hello-worldOnce the test message appears, the hello-world container exits and stops automatically.
Technical Deep Dive: Docker vs Virtual Machines
How Docker Operates
Docker follows a client-server architecture. The Docker daemon runs as a background service on the host machine. Clients communicate with the daemon through socket connections, sending commands to create, manage, and monitor containers on the host system.
Why Docker is Faster Than VMs
Reduced Abstraction Layers:
Unlike virtual machines that require a hypervisor for hardware virtualization, Docker containers share the host system's kernel directly. This results in significantly better CPU and memory utilization.
No Guest OS Overhead:
When creating a new container, Docker does not need to load a separate operating system kernel. Traditional VM creation involves loading a Guest OS, which can take minutes. Docker containers launch in seconds because they utilize the host kernel directly, eliminating the time-consuming kernel boot process.