noted.do
The Tech Guy

Docker, Explained for People Who Don't Use Docker

If you hang around self-hosting forums or developer chats, Docker comes up constantly. Install instructions for half the interesting software out there now start with "run this compose file." If you've never used it, that can feel like the price of entry is learning a whole new thing. It's less than you'd think.

The problem it solves

Software is picky. A web app might need a specific version of PHP or Python, a handful of libraries, certain system packages, some config files in particular places. Install it directly on a server and it works. Then you install a second app that wants a different version of the same library, and now something breaks. Or you move to a new server and spend an afternoon figuring out what you forgot to install.

The classic developer line is "well, it works on my machine." Docker's whole pitch is making the machine part of the package.

Images and containers

Two words do most of the work here.

An image is a packaged-up, read-only bundle of an application plus everything it needs to run: a minimal operating system userland, the runtime, libraries, the app itself, default config. Someone builds it once and publishes it, often on Docker Hub.

A container is a running instance of an image. It's a process on your computer that's been walled off so it sees its own files, its own network setup and its own list of processes. You can run several containers from the same image, and you can throw one away and start a fresh one in seconds.

The analogy I like: an image is like a recipe card that's been fully prepped into a meal kit, and a container is the meal actually cooking. You can make the same kit as many times as you want, and it comes out the same every time.

It's not a virtual machine

People often hear "isolated environment" and picture a virtual machine. A VM emulates an entire computer with its own kernel, which is heavy. Containers share the host's Linux kernel and just isolate the processes. That's why they start almost instantly and you can run a lot of them on modest hardware.

One footnote: on macOS and Windows, Docker Desktop quietly runs a small Linux VM in the background, because containers need a Linux kernel. You don't really have to think about it, but that's why it uses a chunk of memory there.

What it looks like in practice

Here's the smallest useful example. This runs the Nginx web server:

docker run -d -p 8080:80 --name web nginx

Read it left to right. Run a container, in the background (-d), map port 8080 on my computer to port 80 inside the container (-p 8080:80), call it web, and use the nginx image. If you don't have the image yet, Docker downloads it. Open http://localhost:8080 and there's the Nginx welcome page.

When you're done:

docker stop web
docker rm web

And it's gone. Nothing got installed on your actual system.

Volumes: where your data lives

Here's the thing that bites everyone once. Containers are meant to be disposable. When you delete a container, anything written inside it goes too. That's fine for the app's code, which comes from the image, but terrible for your database or uploaded files.

The answer is volumes. A volume is storage that lives outside the container and gets mounted into it. Delete the container, make a new one from an updated image, point it at the same volume, and your data is right where you left it. This is also how updates work: you pull the new image and recreate the container, and the volume carries your data across.

Docker Compose

Real apps usually involve more than one container, like an app plus a database. Typing long docker run commands for each gets old fast. Docker Compose lets you describe the whole setup in one YAML file:

services:
  app:
    image: nginx
    ports:
      - "8080:80"
    volumes:
      - ./site:/usr/share/nginx/html:ro
    restart: unless-stopped

Save that as compose.yaml, put an index.html in a site folder next to it, and run:

docker compose up -d

That's the format most self-hosted projects hand you. Once you can read one of these files (which image, which ports, which volumes, which environment variables), you can read basically all of them. When an app needs secrets like a database password, keep them in a separate .env file that Compose reads, rather than pasting them straight into the YAML you might share or commit.

A couple of honest caveats

Docker isn't magic security. Containers are isolated, but they're not as strongly separated as VMs, and a container running as root with lots of permissions can do real damage if it's compromised. Use images from official or well-maintained sources.

Also, on Linux, ports you publish with Docker can skip right past host firewall rules you set up with tools like ufw, because Docker manages its own firewall rules. If a service only needs to be reached by a reverse proxy on the same machine, bind it to localhost (127.0.0.1:8080:80) instead of exposing it to the world.

And you do still have to update things. Pulling new images and recreating containers is easy, but it's on you to actually do it.

Would I tell someone who just wants to use their computer to learn Docker? No. But if you're curious about running your own services, it's the single most useful tool to pick up, and the basics really do fit in an afternoon.

Comments

Be kind. See the rules.