Docker naming conventions that prevent outages

Published 2026-11-06

Names are an interface

On a single Docker network, the name of a container is also its DNS name. Other containers, the reverse proxy and your own scripts all reach it by that string. Rename it casually and something somewhere stops resolving. When several applications and several environments share hosts, naming stops being cosmetic and becomes part of the contract between systems.

One scheme, applied everywhere

A scheme that works well is app, then environment, then optional role: myapp-prod for the main container and myapp-prod-worker or myapp-prod-db for helpers. The compose service key equals the container name, so what you type in docker compose, what you see in docker ps and what DNS resolves are all the same string.

Every service that builds an image should set the image name explicitly to match. Without it, compose derives a name from the directory, and two checkouts of the same repository for dev and prod can silently produce confusingly similar images.

Keep the tree environment-agnostic

The classic accident is a merge from development into production that carries development names with it. The defence is to keep the repository tree free of environment-specific values and to put them in per-environment files, such as an env file for dev and one for prod that a Makefile copies into place.

Values that differ per environment, hostnames, database names, ports and credentials, then live in exactly one file per environment. Nothing in the compose file hardcodes them, and a merge cannot import the wrong ones.

Renames need a plan

When you do rename a container, treat it as a small migration. Update every reference to the old name: reverse proxy targets, labels used for routing, monitoring probes and scripts. Bring the stack down with orphan removal so the old container does not linger and keep answering on the old name.

One more subtlety: a proxy that bind-mounts its configuration file can keep serving a stale copy after the file is replaced, because the mount points at the old file. Restarting the proxy, rather than only reloading it, avoids chasing a ghost for an hour.

Dollar signs and other small traps

In compose files a literal dollar sign must be written twice, otherwise compose tries to interpolate it. This bites password hashes and shell snippets. Add a pre-deploy check that searches for placeholder strings such as CHANGE_ME, so an unfinished config fails before it reaches a server instead of after.

© 2026 The Good Fellas