StoicBuilder

HandbookX the PortusContainers and Docker

Xthe Portus, Ship it

Containers and Docker

1 min readUpdated 28 November

In plain words

A container runs your app with its own copy of the runtime, libraries and files it needs, started from an image a Dockerfile describes, so it behaves the same on any machine.

Where you see it

Harbor's invoice worker needs Node 22 and a PDF library your teammate's laptop doesn't have. With a Dockerfile in the repository, docker build makes an image and docker run starts it the same way on a laptop, in CI and on the server; docker compose up starts it beside a local Postgres.

Dockerfileconfig
FROM node:22-slimWORKDIR /appCOPY package.json package-lock.json ./RUN npm ci --omit=devCOPY . .USER nodeCMD ["node", "dist/worker.js"]
Copying the lockfile before the code lets Docker reuse the installed packages when only your code has changed.

What goes wrong

  1. Copying secrets into the image

    COPY . . also copies your .env file, and anyone who can pull the image can read it. Add a .dockerignore that excludes .env, .git and node_modules, and pass secrets in when the container starts.

    COPY . . # no .dockerignore, so .env goes in too
  2. Saving data inside the container

    Files written inside a container vanish when it's replaced, which happens on every deploy. Put uploads in object storage and data in a database, or mount a volume.

  3. Building on a moving base image

    FROM node:latest changes underneath you, and one day the build picks up a new major version of Node. Pin the version you tested, such as node:22-slim.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Write a Dockerfile for Harbor's worker with a pinned slim Node base image, a non-root user and a .dockerignore that excludes .env, .git and node_modules. Read every secret from environment variables at runtime, and add a docker-compose.yml that starts it with a local Postgres for development.

Quick check

Sign in to earn +10 XP for it

Harbor's worker saves generated invoice PDFs to /app/invoices inside its container. After the next deploy they're gone. Why?

Got a prompt that touches containers and Docker?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.