A black cargo ship silhouette at the bottom carrying a stack of coloured shipping containers; three abstract containers hover above connected by a thin line, illustrating Docker's shipping-container metaphor for software.
[ OS & Containers ]7 min read

Shipping Containers for Software: Understanding Docker

Phase 1 · The Spark and the Scrap

A docker-compose.yml is a design document. Once you can read one, you can read the whole system.

DockerDocker ComposePi-holeUnbound

The first time I installed three pieces of open-source software on the same Ubuntu VM, they fought like housemates with conflicting allergies. Application A wanted version 2.1 of a shared library. Application B wanted version 3.0 of the same library. Installing one broke the other. Rolling back to make them coexist took an evening, produced a fragile compromise, and left me with the uneasy sense that a package manager alone is not enough. Software that was written ten years apart by people who had never met was now sharing a filesystem, and the filesystem was the reason things were breaking.

Engineers call this dependency hell. The fix is older than you might think: package each application with its exact dependencies so it stops sharing the house. The mechanism that did this at scale, and quietly rewrote how most of the public internet is deployed, is Docker. For the homelab, it is the single technology that turned the workshop from a series of fragile experiments into something durable.

The Analogy

Before the 1950s, global shipping was manual and slow. Barrels of oil, crates of machinery, and sacks of grain were loaded into the hold of a ship by hand, in whatever shape they happened to arrive in. Loading took days. Breakage was routine.

In 1956, a trucker named Malcom McLean loaded fifty-eight identical steel boxes onto a converted tanker called Ideal X. The boxes were the same size regardless of what was inside them. Every crane, every train, and eventually every ship in the world was redesigned to handle that exact size of box. The contents no longer mattered to the system that moved them. Loading a container ship went from days to hours. Cost collapsed. Global trade reshaped itself around the standard.

Docker is that standard for software. Instead of moving a suitcase full of files, dependencies, and environment variables, you hand the server a container: a single, self-contained unit that already knows what it needs to run.

The Tech Translated

A Docker container is a small, isolated environment that bundles an application with every library, binary, and configuration file it expects to find. The container runs as a process on the host’s operating system, but it cannot see the host’s files, network interfaces, or other containers unless you explicitly allow it. That is the whole trick: shared kernel, isolated everything else.

The difference from a virtual machine (the subject of the last entry) is about weight. A virtual machine ships a whole operating system so it can run anywhere. A container ships only the application and its direct dependencies, because it assumes a Linux kernel is already underneath. The practical consequence is that a VM takes a minute to start and uses hundreds of megabytes of memory at rest. A container takes a second to start and uses megabytes.

A docker-compose.yml is a design document

Here is the part designers miss when they first meet Docker. A docker-compose.yml file is not only a deployment tool. It is a declarative description of a whole service, and it reads like an architecture diagram written in plain text. If you can read one, you can reason about the entire system without needing to SSH anywhere.

Here is a compose file for a network-wide ad blocker (Pi-hole) paired with a local DNS resolver (Unbound). One tool blocks advertising at the network level; the other stops your DNS queries from going to a third-party provider. The file describes two containers, their ports, their shared disk volumes, and the private network they sit on. Nothing about the services themselves is installed yet; the file is a blueprint.

# docker-compose.yml — Pi-hole + Unbound on an isolated private network.
services:
  unbound:
    image: mvance/unbound:latest
    container_name: unbound
    restart: unless-stopped
    networks:
      dns-net:
        ipv4_address: 192.0.2.2

  pihole:
    image: pihole/pihole:latest
    container_name: pihole
    restart: unless-stopped
    environment:
      TZ: "Australia/Sydney"
      WEBPASSWORD_FILE: /run/secrets/pihole_pw
      PIHOLE_DNS_: "192.0.2.2#53"     # Send queries to the Unbound container.
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "8081:80/tcp"                 # Web UI on a non-default port.
    volumes:
      - ./pihole/etc:/etc/pihole
      - ./pihole/dnsmasq.d:/etc/dnsmasq.d
    secrets:
      - pihole_pw
    networks:
      dns-net:
        ipv4_address: 192.0.2.3
    depends_on:
      - unbound

networks:
  dns-net:
    driver: bridge
    ipam:
      config:
        - subnet: 192.0.2.0/24

secrets:
  pihole_pw:
    file: ./secrets/pihole_admin_password.txt

Read the file slowly. Without running a single command, you already know: there are two services, they talk to each other on a private 192.0.2.0/24 network, Pi-hole forwards queries to Unbound, the web interface is on port 8081 rather than 80 (so it will not clash with a normal web server), and the admin password lives in a file rather than in the YAML itself. That is a small architecture review, delivered by reading thirty lines of config.

Starting the whole thing is one command:

docker compose up -d

The -d flag means “detached”: the containers run in the background. To stop and remove everything cleanly:

docker compose down

The host is untouched. No half-configured services, no orphaned config files in /etc. If you decide Pi-hole is not for you, the YAML file is the only evidence it was ever installed.

The Action

What broke

The first real compose stack I deployed (a wiki, Nextcloud, and a reverse proxy) lost all of its data the first time I ran docker compose down -v. The -v flag I had copied from a forum post removes volumes. I had written my volumes as anonymous bind mounts without understanding that anonymous volumes get destroyed with the container. The fix is a rule I now apply to every compose file I write: always declare named volumes for anything you want to keep, and never use -v on docker compose down unless you are certain you want to lose data.

volumes:
  nextcloud-data:                # Named volume: survives `docker compose down`.
    driver: local

services:
  nextcloud:
    image: nextcloud:stable
    volumes:
      - nextcloud-data:/var/www/html/data    # Explicit mapping, not anonymous.

The rebuild took an evening. The lesson stuck. Volumes are the only thing in a Docker setup that cannot be described declaratively and recreated from scratch, which means they are the only thing that needs real backups. Everything else (the image, the config, the network) regenerates on command.

The registry rate-limit you will eventually meet

Docker Hub rate-limits unauthenticated image pulls. In 2020 this became a visible problem for small operators and CI systems: pulling the same image more than a hundred times in six hours would be throttled. For a homelab you will rarely hit this, but the lesson is worth internalising early. Images are a supply chain. Depending on a single public registry for everything you run is the same risk profile as depending on a single cloud provider. Many of us responded by running a local pull-through cache or a self-hosted registry (Harbor, Gitea’s image registry, or a simple registry:2 container). We will get to self-hosted infrastructure in a later entry.

Why this changed everything

Once Docker was working, I stopped treating the host operating system as precious. A misbehaving service was no longer a file-system problem to untangle; it was a container to tear down and rebuild from its YAML. The host stayed clean. The services stayed portable. A compose file I wrote on one machine ran unchanged on the next, because the shared contract between them was the container interface, not the file system layout.

That is the shift worth naming. Containers turn infrastructure from a collection of hand-maintained pets into a cattle-farm of declared, disposable units. The pet you still care about is the config file. Protect that, and everything else regenerates.

Footnotes

  1. Levinson, M. (2006). The Box: How the Shipping Container Made the World Smaller and the World Economy Bigger. Princeton University Press. The Ideal X sailed from Newark to Houston on 26 April 1956. ↩

  2. Docker announced the pull rate limits in August 2020 and began enforcing them in November 2020. The current policy is documented at docs.docker.com/docker-hub/download-rate-limit. ↩

Table of Contents