Docker basic concepts
What is containerization technology
Containers share the host kernel and are lightweight, isolated, and efficient, unlike virtual machines that require a full operating system. The figure below shows the basic architecture of a Docker container:
- The upper layer consists of multiple containers (App A-F), each running an application independently.
- The middle layer is Docker, which manages these containers.
- The lower layer is the host operating system (Host OS) and infrastructure, providing hardware and system support for the containers.

1. Pain points of traditional application deployment
In traditional application deployment, we often encounter the following problems:
- Environment inconsistency: The application runs fine in the development environment but has problems in the test or production environment
- Complex dependency management: Different applications require different versions of runtimes, libraries, and so on
- Low resource utilization: Traditional virtual machines require a complete operating system and consume a large amount of resources
- Complex deployment: Requires manual environment configuration and dependency installation, which is error-prone
2. Solutions provided by containerization technology
Containerization technology solves these problems in the following ways:
- Environment standardization: Package the application together with its dependencies to ensure consistent operation in any environment
- Lightweight: Containers share the host's operating system kernel, making them lighter than virtual machines
- Fast deployment: Containers can start within seconds, greatly improving deployment efficiency
- Portability: Build once, run anywhere
3. Core philosophy of containerization
Containerization follows the philosophy of 'immutable infrastructure':
- Applications and environments are packaged into immutable images
- Every deployment uses the same image
- Configuration is injected through environment variables or configuration files
- Problems are fixed by rebuilding the image rather than modifying a running container
Core concepts of Docker
1. Image
define: An image is a read-only template that contains everything needed to run an application: code, runtime, libraries, environment variables, and configuration files.
Feature:
- Layered storage: An image consists of multiple layers, each representing a modification
- Read-only nature: The image itself is read-only and cannot be modified directly
- Reusability: The same image can create multiple containers
- Version Management: Version management through tags
An Analogy: An image is like an installer or a template; it defines everything needed to run the application but cannot be run directly.
2. Container
define: A container is a running instance of an image, a lightweight and portable execution environment.
Feature:
- Isolation: Each container has its own file system, network, and process space
- Ephemerality: Containers can be created, started, stopped, and removed
- Writable layer: A container adds a writable layer on top of the image
- Process-level: A container typically runs one main process
An Analogy: If an image is a class, then a container is an object instance. One image can create multiple containers, just as a class can create multiple objects.
3. Repository
define: A repository is a place for storing and distributing images and can contain multiple versions of an image.
Classification:
- Public repository: Such as Docker Hub, which anyone can use
- Private repository: Built inside an enterprise for storing private images
- Official repository: An image repository maintained by the official software vendor
Registry vs Repository:
- Registry: A registry server, such as Docker Hub
- Repository: A specific image repository, such as nginx or mysql
Differences between Docker and virtual machines
1. Architecture comparison
| Feature | Virtual machine | Docker container |
|---|---|---|
| Isolation level | Hardware-level virtualization | Operating system-level virtualization |
| Operating system | Each VM requires a full OS | Shares the host OS kernel |
| Resource usage | Heavyweight, consumes more resources | Lightweight, consumes fewer resources |
| Startup time | Minute level | Second level |
| Performance overhead | Larger | Close to native performance |
| Image size | GB level | MB level |
2. Container vs. virtual machine architecture

3. Comparison of use cases
Suitable scenarios for virtual machines:
- Environments requiring complete isolation
- Running applications of different operating systems
- Requiring hardware-level security isolation
Suitable scenarios for Docker containers:
- Microservice architecture
- CI/CD pipeline
- Rapid deployment and scaling of applications
- Standardization of development environments
Advantages and application scenarios of Docker
Main advantages
1. Environment consistency
- Problem solving: The 'it works on my machine' problem
- Implementation: The application and environment are packaged together
- Value: Reduces environment-related bugs and deployment issues
2. Lightweight and efficient
- Resource utilization: Consumes fewer resources than virtual machines
- Startup speed: Second-level startup time
- Density: More application instances can run on a single machine
3. Portability
- Cross-platform: Supported on Linux, Windows, and macOS
- Cloud native: Migrate across various cloud platforms
- Hybrid environments: Develop locally, deploy in the cloud
4. Version control and rollback
- Image versions: Each version has a corresponding image
- Fast rollback: Quickly return to the previous version when a problem occurs
- A/B testing: Run different versions simultaneously for comparison
5. Scalability
- Horizontal scaling: Quickly create more container instances
- Elastic scaling: Automatically adjust the number of containers based on load
- Microservices: Service splitting and independent deployment
Typical use cases
1. Microservice architecture
- Service splitting: Each microservice is containerized independently
- Independent deployment: Services can be updated and scaled independently
- Freedom of technology stack: Different services can use different technologies
2. CI/CD pipeline
- Build environment: Standardized build environment
- Test isolation: Each test runs in an independent container
- Deployment consistency: The same image is deployed in different environments
3. Development environment standardization
- Quick setup: New members quickly obtain a development environment
- Version synchronization: The team uses the same development environment
- Dependency Management: Avoid local environment conflicts
4. Application modernization
- Legacy systems: Containerize traditional applications
- Cloud migration: Help applications migrate to cloud platforms
- Hybrid cloud: Port across different cloud environments
Docker architecture components
Overall architecture diagram

Docker Client
Function:
- The main way users interact with Docker
- Receive user commands and send them to the Docker Daemon
- Can communicate with a remote Docker Daemon
Common Commands:
docker run- Run containersdocker build- Build imagesdocker pull- Pull imagesdocker ps- Check container status
Docker Daemon
Function:
- Docker's core service process
- Manage images, containers, networks, and storage volumes
- Listen for and handle Docker API requests
Main responsibilities:
- Image management (build, storage, distribution)
- Container Lifecycle Management
- Network management
- Data volume management
- Communicate with the Registry
Docker Engine
Component:
- Docker Client + Docker Daemon + REST API
- Is a core component of Docker
Workflow:
- The Client sends commands to the Daemon
- The Daemon parses and executes commands
- Interact with the Registry (if needed)
- Manage local images and containers
- Return results to the Client
Docker Registry
Purpose:
- Store and distribute Docker images
- Provide image version management
- Support public and private repositories
Features of Docker Hub:
- Official public Registry
- Contains a large number of pre-built images
- Supports automated builds
- Free and paid services
The development history of Docker
Key milestones
- 2013: Docker released as open source
- 2014: Docker 1.0 released, ready for production
- 2016: Docker Swarm released with built-in orchestration
- 2017: Docker split into CE (Community Edition) and EE (Enterprise Edition)
- 2019: Docker Desktop released, improving developer experience
Ecosystem development
- Container orchestration: Kubernetes became the de facto standard
- Container runtime: Alternatives such as containerd and CRI-O
- Image format: The OCI standard was established
- Security tools: Container security scanning and monitoring tools