Skip to content

01. Introduction to Docker

Docker completely revolutionized how software is built, shipped, and run. By packaging applications into lightweight, portable containers, Docker ensures that an application runs identically on a developer’s laptop, a testing server, and in production.

Docker is an open-source platform that enables developers to automate the deployment of applications inside lightweight, portable environments called containers.

Containerization is a type of operating-system-level virtualization. Instead of virtualizing the hardware (like a VM does), containerization virtualizes the OS. Applications are bundled with their dependencies, libraries, and configuration files into a single immutable package.

  • Virtual Machines include the application, dependencies, and a full guest operating system. They require a hypervisor, consume heavy CPU/Memory overhead, and take minutes to boot.
  • Containers share the host system’s kernel. They package only the application and its dependencies. They are extremely lightweight, consume minimal resources, and boot in milliseconds.
  • Consistency: “It works on my machine” is no longer an excuse. The environment is guaranteed to be identical everywhere.
  • Speed: Containers start instantly because there is no OS boot process.
  • Isolation: Applications run in isolation without interfering with each other.
  • Resource Efficiency: You can pack far more containers onto a single server compared to VMs.
  • Microservices architectures
  • Continuous Integration / Continuous Deployment (CI/CD) pipelines
  • Standardized local development environments
  • Cloud-native scalable applications

In the DevOps lifecycle, Docker acts as the ultimate bridge between Development and Operations. Developers write the code and the Dockerfile (the environment), and Operations simply runs the resulting container without worrying about installing specific programming languages or libraries on the host server.

Docker uses a client-server architecture.

The primary interface you use to interact with Docker. When you run commands like docker run or docker build, the client sends these commands to the Docker Daemon via a REST API.

The core software that runs and manages containers. It consists of the Docker Client, the REST API, and the Docker Daemon.

The background service running on the host machine. It listens for API requests and actually does the heavy lifting of building images, running containers, and managing networks/volumes.

The physical or virtual machine running the Docker Daemon.

A scalable service that stores and distributes Docker images (like GitHub, but for compiled containers).

  • Public Registries: Docker Hub, GHCR (GitHub).
  • Private Registries: AWS ECR, GCP Artifact Registry.

The default, massive public registry maintained by Docker. It hosts millions of official and community images (e.g., nginx, postgres, ubuntu).

The REST API used by the Client to instruct the Daemon. You can also interact with this API programmatically using scripts or tools like Portainer.

The fundamental building blocks you will interact with daily:

Read-only templates used to create containers. An image contains the application code, libraries, and tools required to run the app. Images are built in layers to maximize reuse and reduce size.

The runnable instance of an image. You can start, stop, move, or delete a container. It is an isolated sandbox running on the host machine.

Networks allow containers to communicate with each other, the host machine, and the outside internet, all while maintaining isolation from containers on other networks.

By default, data created inside a container is lost when the container is deleted. Volumes are used to persist data (like databases) outside the container’s lifecycle directly onto the host machine.

Extensions that add capabilities to Docker Engine, primarily used for advanced networking (third-party network drivers) and specialized volume storage (like AWS EBS or NFS).

The journey of an application from code to a running container follows a strict lifecycle:

Dockerfile
↓ (Build)
Image
↓ (Run)
Container
↓ (Stop)
Stopped Container
↓ (Remove)
Deleted
  1. Dockerfile: You write a text file containing the instructions to build your environment.
  2. Build: You execute docker build, which reads the Dockerfile and compiles it into a read-only Image.
  3. Run: You execute docker run, which takes the Image and spins up a live, isolated Container.
  4. Stop: You execute docker stop to gracefully halt the container process. The container still exists on disk.
  5. Remove: You execute docker rm to permanently delete the container instance. (The image remains until explicitly removed).