Oh My AlgorithmKO
←
Docker
← All catalogs

Docker

Containers, images, networking, and storage

Docker Architecture

Pull an image, then run a container.

ClientDocker HostRegistryacross the networkDocker Hostdocker builddocker pulldocker runDocker daemondockerdImagesnginxredismy-appContainersnginx-1nginx-2redisDocker Hubnginxredisubuntu
↔ Drag to explore
Principles and uses

Follow commands through the Docker client, host, and registry.

The daemon handles client requests and retrieves images from a registry.

An image provides read-only filesystem content and configuration. Multiple containers can be created from the same image.

Use it to distinguish pull, build, and run and locate image storage and command execution.

Layers & Size

A Docker image consists of read-only layers created by filesystem-changing build instructions.

DockerfileFROM node:20-alpineRUN apk add python3 make g++WORKDIR /appCOPY package*.json ./RUN npm ciCOPY . .RUN npm run buildImagesFiles visible to the container
↔ Drag to explore
Principles and uses

Explore image layers, build caching, and multi-stage builds.

Reuse unchanged build steps and include only runtime files in the final image.

Copy dependency manifests before source for cache reuse. Separate build tools from runtime files. Displayed sizes and times are examples.

Use it to understand Dockerfile ordering, cache invalidation, and image-size reduction.

Container vs Virtual Machine

Virtual machines · Separate guest operating systems

A virtual machine runs a guest operating system and applications on a hypervisor.

Virtual machine serverPhysical server · CPU · RAM · DiskHost OSHypervisor · hardware virtualizationApp A · 20 MBBins / Libs120 MBGuest OSkernel · 2 GBApp B · 20 MBBins / Libs120 MBGuest OSkernel · 2 GBApp C · 20 MBBins / Libs120 MBGuest OSkernel · 2 GB——
↔ Drag to explore

Container · Sharing the Host Kernel

Containers share the host kernel and package the application with its required libraries.

Virtual machine serverPhysical server · CPU · RAM · DiskHost OSHypervisor · hardware virtualizationApp A · 20 MBBins / Libs120 MBGuest OSkernel · 2 GBApp B · 20 MBBins / Libs120 MBGuest OSkernel · 2 GBApp C · 20 MBBins / Libs120 MBGuest OSkernel · 2 GBContainer serverPhysical server · CPU · RAM · DiskHost OS kernel — shared by allDocker Engine · containerd · runcApp A · 20 MBBins / Libs120 MBApp B · 20 MBBins / Libs120 MBApp C · 20 MBBins / Libs120 MB6.4 GB420 MBstart 0.4 sGuest OS ×0
↔ Drag to explore
Principles and uses

Compare how virtual machines and containers use operating systems and kernels.

VMs run separate guest operating systems; containers share the host kernel.

Containers avoid guest-OS boot overhead but share the kernel. Namespaces and cgroups isolate and control resources. Containers can also run within VMs.

Use it to compare isolation, startup costs, resource use, and OS compatibility.

Container Lifecycle

Follow how Docker commands create, start, pause, stop, and remove a container.

Docker statescreatestartpauseunpausestopstartrmmy-api:1.0CreatedRunningPausedExitedRemovedContainer apino processmemory 0 Bno writable layerimage · read-onlymy-api:1.0
↔ Drag to explore
Principles and uses

Follow creation, startup, pausing, stopping, and removal of a container.

Stopping ends the process; removal also deletes the writable layer.

Run combines creation and startup. Stop signals termination and can force it after a timeout. Restarting the same stopped container preserves its writable layer.

Use it to interpret states, distinguish stopping from removal, and choose persistent storage.

Volumes & Data

No volume · Container-local storage

Without a volume, database files are stored in the container writable layer.

dbpostgres:16.3postgres · PID 1Writable layer5,584 rowsimage · read-onlyHost filesystemempty · 0 Brow
↔ Drag to explore

With a volume · External storage

Volumes and bind mounts connect external storage to a directory inside the container.

dbpostgres:16.3postgres · PID 1/var/lib/postgresql/dataWritable layer0 Bimage · read-onlyapinode:20-alpinenode · PID 1Writable layer0 Bimage · read-onlyHost filesystempgdata/var/lib/docker/volumes/pgdata/_data./src~/shop/src · index.js12,408 rows · 48 MB
↔ Drag to explore
Principles and uses

Compare data lifetimes in writable layers, volumes, and bind mounts.

Store files outside the container when they must survive its replacement.

Docker manages named-volume locations; bind mounts use specified host paths. External storage can be managed separately from containers.

Use it for database persistence, uploads, and development source sharing.

Networking & Ports

Three containers join the user-defined app-net network, each with its own IP address.

OutsideBrowserHostapp-net · bridge172.18.0.0/16other-net:8080:3000 closed:5432 closedNATweb172.18.0.2 · :80api172.18.0.3 · :3000db172.18.0.4 · :5432DNS127.0.0.11DNS127.0.0.11workerother-net
↔ Drag to explore
Principles and uses

Explore name-based Docker networking and published ports.

Containers on a user-defined network connect by name; external access uses published host ports.

Port mappings forward host traffic to a container port. Separate bridge networks isolate traffic by default and require explicit communication settings.

Use it to design container connections and distinguish internal ports from externally reachable endpoints.

Registry push & pull

A registry stores image manifests and layers. Each manifest identifies its layers by digest.

Developer PCmyapp:1.2.0manifest c07e9f2c · dist/12 MBe44a · node_modules60 MBb90d · package.json0.5 MB7c2e · node127 MBa1f3 · alpine8 MB12 / 207.5 MBRegistryacross the networkTagsmyapp:1.1.0 → 41abblobs9f2c e44a b90d 7c2e a1f3 manifests41abdeploy servermyapp:1.1.0manifest 41ab51d8 · dist/12 MBe44a · node_modules60 MBb90d · package.json0.5 MB7c2e · node127 MBa1f3 · alpine8 MBmyapp:1.1.0 running
↔ Drag to explore
Principles and uses

Follow image upload to a registry and download to a deployment server.

Read a manifest and transfer only missing layers.

Content digests identify layers. Tags can change their target, while a digest identifies specific content.

Use it to understand image distribution, tags versus digests, and transfer reuse.

Multi-Container (Docker Compose)

Running containers with separate commands also requires managing their networks and volumes individually.

compose.yamlcompose.yamlTerminaldocker network create shopdocker volume create pgdatadocker run -d --name db \ --network shop -v pgdata:/var/lib/ postgresql/data postgres:16docker run -d --name api \ --network shop node:20-alpinedocker run -d --name web \ --network shop -p 8080:80 nginxBrowserHostshop_defaultNetworkshop-web-1nginx:1.27shop-api-1build: . · DB_HOST=dbshop-db-1postgres:16shop_pgdatapgdata
↔ Drag to explore
Principles and uses

Define and run services, networks, and volumes together in a Compose file.

Save repeatable configurations and connect containers by service name.

Startup ordering differs from readiness. Health checks and readiness conditions can delay dependent startup until a service accepts connections.

Use it to manage multi-container application environments.

Learning topics