Introduction: The Era of Container Technology

In modern software development and deployment environments, Docker has become an essential technology. The phrase "It works on my machine..." has long been a joke among developers, but with the advent of Docker, this problem has become a thing of the past.

In this series, we will systematically learn from the basic concepts of Docker to large-scale container orchestration using Kubernetes. In this first part, we will cover container technology concepts, Docker architecture, installation methods, and how to run your first container.

1. What is Container Technology?

1.1 Definition of Containers

A Container is a technology that packages an application and all its dependencies (libraries, configuration files, binaries, etc.) into a single package and runs it in an isolated environment.

Containers share the host operating system's kernel while having their own independent file system, network, and process space. This allows applications to run identically in any environment.

1.2 Core Concepts of Container Technology

  • Isolation: Each container runs in an independent environment without affecting other containers or the host system.
  • Portability: Containers run identically anywhere. There are no differences between development, testing, and production environments.
  • Lightweight: Unlike virtual machines, containers don't include an entire OS, enabling fast startup and minimal resource usage.
  • Immutability: Container images, once created, don't change, and the same image can always reproduce the same environment.

2. Virtual Machines vs Containers Comparison

2.1 Virtual Machine (VM) Architecture

Traditional virtualization technology, virtual machines, install independent operating systems (Guest OS) on top of a Hypervisor:

+-------------------------------------------------------------+
|                      Applications                            |
+-------------------------------------------------------------+
|   Guest OS  |   Guest OS  |   Guest OS  |   Guest OS        |
+-------------------------------------------------------------+
|                     Hypervisor                               |
+-------------------------------------------------------------+
|                      Host OS                                 |
+-------------------------------------------------------------+
|                      Hardware                                |
+-------------------------------------------------------------+

2.2 Container Architecture

Containers share the host OS kernel, with the Container Runtime handling isolation:

+-------------------------------------------------------------+
|  Container  |  Container  |  Container  |  Container        |
|   + App     |   + App     |   + App     |   + App           |
+-------------------------------------------------------------+
|                   Container Runtime                          |
+-------------------------------------------------------------+
|                       Host OS                                |
+-------------------------------------------------------------+
|                       Hardware                               |
+-------------------------------------------------------------+

2.3 Comparison Table

Aspect Virtual Machine (VM) Container
Startup Time Minutes (OS boot required) Seconds (process start)
Resource Usage GB-level (includes entire OS) MB-level (app + dependencies)
Isolation Level Complete hardware-level isolation Process-level isolation
Portability Hypervisor dependent Runs identically anywhere
Density Dozens per server Hundreds per server
Use Cases Running different OS, complete isolation needed Microservices, CI/CD, development environments

3. Docker History and Advantages

3.1 The Birth of Docker

Docker was first released in 2013 by Solomon Hykes at a PaaS company called dotCloud (now Docker, Inc.). It started based on Linux container (LXC) technology, but later developed its own container runtime called libcontainer to become a more independent platform.

Container technology existed before Docker (chroot, FreeBSD Jail, Solaris Zones, LXC, etc.), but Docker succeeded in popularizing it by making it easy and standardized to use.

3.2 Key Advantages of Docker

  • Development-Production Environment Consistency: Solves the "Works on my machine" problem. Development, testing, and production environments are identical.
  • Fast Deployment: Applications can be deployed in seconds through container images.
  • Efficient Resource Usage: Run more applications with far fewer resources compared to VMs.
  • Microservices Architecture Support: Each service can be separated and managed as an independent container.
  • Version Control: Various versions of applications can be managed through image tags.
  • Scalability: Easy horizontal scaling by creating multiple containers from the same image.
  • Community and Ecosystem: Access to millions of public images through Docker Hub.

4. Docker Architecture

Docker uses a client-server architecture. Let's look at the main components.

4.1 Docker Engine

Docker Engine is the core component of Docker, responsible for creating and running containers. It consists of three main components:

  • Docker Daemon (dockerd): Runs in the background and manages Docker objects (images, containers, networks, volumes).
  • REST API: Provides an interface for communicating with the Daemon.
  • Docker CLI (docker): Command-line interface for users to control Docker.

4.2 Docker Client

The Docker Client is the primary way users interact with Docker. When you use the docker command, the client sends this command to the Docker Daemon, which executes it.

# User enters command
docker run nginx

# Docker Client sends request to Docker Daemon
# Docker Daemon downloads nginx image and runs container

4.3 Docker Daemon

The Docker Daemon (dockerd) receives Docker API requests and manages Docker objects. Multiple Daemons can communicate with each other to manage Docker services.

4.4 Docker Objects

  • Image: A read-only template for creating containers.
  • Container: A runnable instance of an image.
  • Network: An isolated network for communication between containers.
  • Volume: A space for persistently storing container data.

4.5 Docker Architecture Diagram

+--------------------------------------------------------------+
|                        Docker Host                            |
|  +----------------------------------------------------------+ |
|  |                    Docker Daemon                         | |
|  |  +------------+  +------------+  +-------------------+   | |
|  |  |  Images    |  | Containers |  | Networks/Volumes  |   | |
|  |  +------------+  +------------+  +-------------------+   | |
|  +----------------------------------------------------------+ |
|                            ^                                  |
|                            | REST API                         |
|                            v                                  |
|  +----------------------------------------------------------+ |
|  |                    Docker CLI                            | |
|  +----------------------------------------------------------+ |
+--------------------------------------------------------------+
                            ^
                            |
                            v
             +--------------------------+
             |      Docker Registry     |
             |      (Docker Hub)        |
             +--------------------------+

5. Docker Installation

Docker can be installed on all platforms: Windows, macOS, and Linux. Let's look at the installation methods for each operating system.

5.1 Installing Docker on Windows

Requirements:

  • Windows 10 64bit: Pro, Enterprise, Education (Build 19041 or higher)
  • Windows 11 64bit: Home, Pro, Enterprise, Education
  • WSL 2 (Windows Subsystem for Linux 2) enabled
  • Hardware virtualization support (enabled in BIOS)

Installation Steps:

  1. Download Docker Desktop for Windows from the official Docker website.
  2. Run the downloaded Docker Desktop Installer.exe.
  3. Select the "Use WSL 2 instead of Hyper-V" option during installation.
  4. Restart the system after installation is complete.
  5. Launch Docker Desktop and agree to the terms of service.
# Verify installation (in PowerShell)
docker --version
docker run hello-world

5.2 Installing Docker on macOS

Requirements:

  • macOS 12.0 (Monterey) or higher
  • Apple Silicon (M1/M2/M3) or Intel processor
  • Minimum 4GB RAM

Installation Steps:

  1. Download Docker Desktop for Mac from the official Docker website.
  2. Open the downloaded Docker.dmg file and drag Docker to the Applications folder.
  3. Launch Docker from Applications.
  4. Approve system permission requests.
# Alternative installation using Homebrew
brew install --cask docker

# Verify installation
docker --version
docker run hello-world

5.3 Installing Docker on Linux (Ubuntu/Debian)

On Linux, you install Docker Engine directly:

# Remove existing Docker packages
sudo apt-get remove docker docker-engine docker.io containerd runc

# Install required packages
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release

# Add Docker official GPG key
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Add Docker repository
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Add current user to docker group (use docker without sudo)
sudo usermod -aG docker $USER

# Apply changes (logout and login again or)
newgrp docker

# Verify installation
docker --version
docker run hello-world

5.4 Installing Docker on Linux (CentOS/RHEL)

# Install required packages
sudo yum install -y yum-utils

# Add Docker repository
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# Install Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker

# Add current user to docker group
sudo usermod -aG docker $USER

# Verify installation
docker --version
docker run hello-world

6. Running Your First Container

6.1 Hello World Container

The simplest way to verify that Docker is installed correctly is to run the hello-world image:

docker run hello-world

Output:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:53641cd209a4fecfc68e21a99871ce8c6920b2e7502df0a20671c6fccc73a7c6
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
...

6.2 nginx Web Server Container

Now let's run an nginx web server as a container that you can actually use:

# Run nginx container
docker run -d -p 8080:80 --name my-nginx nginx

# Option explanation:
# -d: Run in background (detached mode)
# -p 8080:80: Connect host port 8080 to container port 80
# --name my-nginx: Assign a name to the container
# nginx: Image name to use

Access http://localhost:8080 in your browser to see the nginx welcome page.

# Check running containers
docker ps

# Example output:
CONTAINER ID   IMAGE   COMMAND                  CREATED          STATUS          PORTS                  NAMES
a1b2c3d4e5f6   nginx   "/docker-entrypoint..."  10 seconds ago   Up 9 seconds    0.0.0.0:8080->80/tcp   my-nginx

# Check container logs
docker logs my-nginx

# Stop container
docker stop my-nginx

# Start container
docker start my-nginx

# Remove container (after stopping)
docker stop my-nginx
docker rm my-nginx

6.3 Running Interactive Containers

You can also access the inside of a container directly and run commands:

# Access Ubuntu container interactively
docker run -it ubuntu bash

# Option explanation:
# -i: Interactive mode
# -t: Allocate TTY (terminal)
# ubuntu: Image to use
# bash: Command to execute

# Run commands inside container
root@container_id:/# cat /etc/os-release
root@container_id:/# apt update
root@container_id:/# exit  # Exit container

7. Introduction to Docker Hub

7.1 What is Docker Hub?

Docker Hub is a cloud-based registry service for storing and sharing Docker images. If GitHub is for source code, Docker Hub is for Docker images.

  • Public Repositories: Store unlimited public images for free.
  • Private Repositories: Store private images with paid plans.
  • Official Images: Provides official images verified by Docker.
  • Automated Builds: Integration with GitHub/Bitbucket for automated image builds.

7.2 Using Docker Hub

# Search for images on Docker Hub
docker search nginx

# Example output:
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                             Official build of Nginx.                        19000     [OK]
linuxserver/nginx                 An Nginx container...                           200

# Download (pull) image
docker pull nginx
docker pull nginx:1.25  # Specify version

# Log in to Docker Hub (for pushing images)
docker login

# Tag your image
docker tag my-image:latest username/my-image:latest

# Upload (push) image to Docker Hub
docker push username/my-image:latest

7.3 Major Official Images

Image Description Example Command
nginx High-performance web server docker run -d -p 80:80 nginx
mysql MySQL database docker run -d -e MYSQL_ROOT_PASSWORD=pass mysql
postgres PostgreSQL database docker run -d -e POSTGRES_PASSWORD=pass postgres
redis In-memory data store docker run -d -p 6379:6379 redis
node Node.js runtime docker run -it node
python Python runtime docker run -it python:3.11
ubuntu Ubuntu Linux docker run -it ubuntu bash
alpine Lightweight Linux (5MB) docker run -it alpine sh

8. Conclusion and Next Steps

In this Part 1, we've covered the basic concepts of container technology, Docker architecture, installation methods, and how to run your first container.

Key Summary

  • Containers are technology that packages applications and dependencies to run in isolated environments.
  • Difference from VMs: Containers share the host OS kernel, making them lighter and faster.
  • Docker Architecture: Client-Server structure consisting of Docker CLI, Docker Daemon, and Docker Registry.
  • Basic Commands: docker run, docker ps, docker stop, docker rm
  • Docker Hub: A registry service for storing and sharing Docker images.

Preview of Next Part

In Part 2, we will dive deeper into Docker Images and Container Management:

  • Difference between images and containers
  • Image layer concept
  • docker pull/push/images/rmi commands
  • Container lifecycle management
  • Detailed docker run options (-d, -p, -v, -e, --name)
  • docker exec and attach
  • Container logs and resource limits

Container technology is at the heart of modern software development. Mastering Docker will allow you to build more efficient development environments and deployment pipelines. Let's learn more practical Docker usage in the next part!