Cloud Native 13 min read

Unlocking Docker: From Containers to Compose, Swarm, and Kubernetes

This article explains Docker’s role as a container platform, covering basic concepts like images and Dockerfiles, the architecture of Docker Engine, and how Docker Compose, Swarm, and Kubernetes extend container orchestration across multiple services and hosts.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Unlocking Docker: From Containers to Compose, Swarm, and Kubernetes

Programmers often face environment inconsistencies when deploying software; Docker provides a middle layer that packages both the application and its runtime environment into portable containers.

What is Docker?

Docker is a tool that bundles a program with its required operating‑system libraries and configurations, creating a self‑contained environment that can run on any host without dependency issues.

Base Image

A base image is a minimal filesystem containing an operating‑system layer and essential language runtimes (e.g., Python, Java). It serves as the foundation for building custom images.

Dockerfile

A Dockerfile lists the steps needed to assemble an image, similar to a todo list. Example:

# Specify base image
FROM python:3.9

# Set working directory
WORKDIR /app

# Copy dependency file
COPY requirements.txt .

# Install system packages
RUN yum install gcc
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . /app

# Define container start command
CMD ["python", "app.py"]

Running docker build processes this file to produce a container image.

Container Image

The built image is a compressed package of the base OS layer plus the application and its dependencies. docker push uploads the image to a registry; docker pull retrieves it on another host.

Docker Registry

A registry (e.g., Docker Hub, private registries) stores and distributes images, analogous to a Git repository for code.

Containers vs. Virtual Machines

Unlike full VMs, containers share the host kernel and only include user‑space libraries, making them lightweight special processes.

Docker Architecture

Docker follows a client‑server model: the Docker CLI sends commands to the Docker daemon via a RESTful API. The daemon delegates tasks to the Engine, which creates jobs for actions such as build, pull/push, and run.

docker build

Executes the Dockerfile step‑by‑step, layering the image like an onion.

docker pull / docker push

Interact with a Docker Registry to download or upload images.

docker run

Creates a container from an image using containerd and runC.

Docker Compose

Compose uses a YAML file to define multiple services, their images, resource limits, and startup order. Example:

version: "3.8"
services:
  A:
    image: "some-image-for-a"
    deploy:
      resources:
        limits:
          cpus: "0.50"   # 50% CPU
          memory: 256M      # 256 MB
  B:
    image: "some-image-for-b"
    depends_on:
      - A
  C:
    image: "some-image-for-c"
    depends_on:
      - B

Running docker‑compose up launches the defined services in the correct order.

Docker Swarm

Swarm extends Docker to orchestrate a set of containers across multiple hosts, providing high‑availability and scaling similar to Kubernetes.

Docker and Kubernetes

Kubernetes (k8s) schedules Pods, each of which may contain one or more containers. Docker containers are the same entities that k8s runs as part of Pods. Docker Compose defines a multi‑container application, which corresponds to a single Pod in k8s. Swarm and k8s are competing orchestration solutions.

Summary

Docker packages programs and their environments into portable containers that run as isolated processes on the host kernel.

Dockerfiles describe how to build images; docker build, docker pull/push, and docker run manage the lifecycle.

Docker Compose handles multi‑container services, Docker Swarm adds multi‑host clustering, and Kubernetes provides a broader orchestration platform compatible with Docker images.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeDockerKubernetesDockerfilecontainer orchestrationContainersDocker Compose
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.