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.
What goes wrong
- 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 - 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.
- 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
Quick check
Sign in to earn +10 XP for itHarbor's worker saves generated invoice PDFs to /app/invoices inside its container. After the next deploy they're gone. Why?