Skip to content

How to use containers well

Run one process per container, keep images small, never run as root, and treat containers as ephemeral.

Containers that behave

  1. One process per container

    A container with a process supervisor (systemd, supervisord) is fighting the model. Split into two containers.

  2. Keep images small

    alpine or distroless instead of ubuntu:latest. Smaller image = faster pull, fewer CVEs.

  3. Never run as root

    USER appuser in the Dockerfile. A root container shares the host's root kernel capabilities.

  4. Treat containers as ephemeral

    Data goes in volumes, logs go to stdout, state goes to a database. The container is disposable.

  5. Pin image digests

    image@sha256:... in production. Tags move; digests do not.