Docker Fundamentals

Core concepts of Docker containerization — the essential prerequisite for Kubernetes and CKA.

What is Docker?

Docker is an open-source platform for developing, shipping, and running applications inside lightweight, portable containers. It solves the “it works on my machine” problem by packaging code with all its dependencies into a standardized unit.

VMs vs. Containers

AspectVirtual MachinesContainers
ArchitectureHeavy — each VM includes a full OS kernelLightweight — shares the host OS kernel
Boot TimeMinutesSeconds
Resource UsageHigh (GBs of RAM per VM)Low (MBs of RAM per container)
IsolationHardware-level (Hypervisor)OS-level (cgroups + namespaces)
PortabilityHard to move across environmentsPackaged as images, runs anywhere
Use CaseMulti-OS environments, legacy appsMicroservices, CI/CD, cloud-native apps

Docker Architecture

┌─────────────────┐
│   Docker Client │  ← `docker` CLI commands
│     (docker)    │
└────────┬────────┘
         │ REST API
┌────────▼────────┐
│  Docker Daemon  │  ← `dockerd` — manages images, containers, networks, volumes
│   (dockerd)     │
└────────┬────────┘
         │
┌────────▼────────┐
│ Docker Registry │  ← Docker Hub, ECR, GCR, private registries
│  (docker hub)   │
└─────────────────┘
  • Docker Client (docker CLI): The command-line interface users interact with.
  • Docker Daemon (dockerd): The background service that builds, runs, and distributes containers.
  • Docker Registry: Stores and distributes Docker images (public Docker Hub or private registries).
  • Docker Image: A read-only template containing application code, libraries, and environment settings.
  • Docker Container: A runnable instance of an image — isolated, portable, and ephemeral.

The Docker Workflow

  1. Write a Dockerfile — defines the image blueprint (base OS, dependencies, code, entrypoint).
  2. Build an image — docker build -t myapp:1.0 .
  3. Run a container — docker run -d -p 8080:80 myapp:1.0
  4. Push to registry — docker push myapp:1.0
  5. Pull & deploy — docker pull myapp:1.0

Essential Docker Commands

CommandPurposeExample
docker runCreate and start a containerdocker run -d -p 80:80 nginx
docker psList running containersdocker ps
docker ps -aList all containersdocker ps -a
docker stopGracefully stop a containerdocker stop <container_id>
docker startStart a stopped containerdocker start <container_id>
docker rmRemove a stopped containerdocker rm <container_id>
docker imagesList local imagesdocker images
docker rmiRemove an imagedocker rmi <image_id>
docker logsView container logsdocker logs <container_id>
docker execExecute a command inside a running containerdocker exec -it <id> /bin/sh
docker buildBuild an image from a Dockerfiledocker build -t myapp:1.0 .
docker pullDownload an image from a registrydocker pull nginx:latest
docker pushUpload an image to a registrydocker push myapp:1.0

Container Lifecycle

    docker create
┌──────────────┐
│   CREATED    │
└──────┬───────┘
       │ docker start / docker run
┌──────▼───────┐
│   RUNNING    │◄────────────────┐
└──────┬───────┘                 │
       │ docker pause             │ docker restart
┌──────▼───────┐                 │
│   PAUSED     │─────────────────┘
└──────┬───────┘
       │ docker unpause
       │ docker stop
┌──────▼───────┐
│   STOPPED    │
└──────┬───────┘
       │ docker rm
┌──────▼───────┐
│   DELETED    │
└──────────────┘

Docker & Kubernetes Relationship

  • Kubernetes is a container orchestrator — it manages Docker containers at scale.
  • Kubernetes does not run containers directly; it instructs a Container Runtime Interface (CRI) like containerd or CRI-O.
  • containerd was originally part of Docker but is now an independent CNCF project — the runtime Kubernetes uses under the hood.
  • Understanding Docker helps you debug Kubernetes pods: kubectl describe pod, kubectl logs, kubectl exec.
  • Docker alone lacks auto-healing and replication. Kubernetes solves this with Deployments and ReplicaSets that continuously recreate failed containers. Source: CKA Day 8

Sources


Tags: docker containers devops cka kubernetes fundamentals