Skip to the workspace
Pebellslearn by building
Installation and Setup  ›  Lesson

Planning What Goes in a Container

Application Architecture 14 minGive each separately running part of an application its own container, carry the language runtime inside the image, and keep configuration and data outside it.

docker / Planning What Goes in a Container

Explore each scene at your own pace.

01 · The rule

The rule

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 postgres image.

What goes inside an image depends on the language:

  • Interpreted languages (Python, JavaScript, Ruby) need their runtime in the image: python:3.12-slim supplies 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.0

The same quicknotes:1.0 image can point at a test database or a production one, just by changing -e.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.