Planning What Goes in a Container
Before installing anything, decide what you are going to containerise. quicknotes is a Python web app that will soon store its notes in PostgreSQL. Do you put both in one container? Where does the database password go? Where do the notes themselves live? A few minutes of planning here saves hours later.
The rule
One container, one concern: the app here, the database there.
A container is built around one main process. When it exits, the container stops. So each part of your system that runs, restarts, updates or scales on its own gets its own container:
- quicknotes web app → one container, from an image you build.
- PostgreSQL → a second container, from the official
postgresimage.
What goes inside an image depends on the language:
- Interpreted languages (Python, JavaScript, Ruby) need their runtime in the image:
python:3.12-slimsupplies the interpreter, then your libraries and code go on top. - Compiled languages (Go, Rust) can ship just the finished program, so their final images can be tiny.
What stays outside the image:
- Configuration and secrets, such as the database password or which host to connect to. Pass them in when the container starts, commonly as environment variables, so one image works in every environment.
- Data, such as the notes. Containers are meant to be replaced; data must live in storage that outlives them.
docker run -d --name notes -e DATABASE_HOST=notes-db quicknotes:1.0The same quicknotes:1.0 image can point at a test database or a production one, just by changing -e.