Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction  ›  Lesson

Why Containers Exist

Why do we need Containers? 12 minContainers ship an application together with its exact environment, so it behaves the same on every machine and apps with clashing dependencies can live side by side.

Why Containers Exist

quicknotes works perfectly on your laptop. You copy it to the team server and it crashes on start-up: the server has Python 3.8, and your code uses a feature added in 3.10. Worse, another app on that server needs 3.8, so you cannot simply upgrade. This is the everyday pain containers were built to remove.

The rule

Ship the environment with the code, and "works on my machine" disappears.

A program never runs alone. It depends on a language runtime, libraries, system packages, configuration files and sometimes exact versions of all of them. Traditionally, you shipped only the code and hoped each machine had the right environment. A container image ships both:

  • Consistency. The quicknotes image carries Python 3.12 and every library from requirements.txt. Laptop, test server and cloud all run the same bytes.
  • Side-by-side isolation. The 3.8 app and quicknotes each bring their own runtime, so they never fight over one shared installation.
  • Speed and density. A container starts in about a second and weighs megabytes, so one server can hold many of them.
  • Easy onboarding. A new teammate runs one command instead of following a page of setup notes.
  • Clean removal. Delete the container and nothing is left scattered across the machine.
docker run -d -p 8080:5000 quicknotes:1.0

That same line works on any machine with Docker, whatever is or is not installed there.

The shortcut

When a problem appears, ask "Is this a difference in environment?" If the same code behaves differently on two machines, containers are the cure. If the code is simply wrong, or the hardware failed, they are not.

Diagnosing three quicknotes problemsStep 1 of 3
  1. Crash on the server only

    It works on the laptop, fails on the server, same code. That is an environment difference: containers fix it.

Containers also have limits you should know from day one. They share the host's kernel, so a Linux container needs a Linux kernel underneath, and their isolation is thinner than a virtual machine's. They package an environment; they do not make bad code good.

Drills

Answer fast — trust the rule.

quick drill

Which problem do containers solve most directly?

quick drill

Two apps on one server need Python 3.8 and Python 3.12. What is the container approach?

quick drill

quicknotes has an off-by-one bug on every machine. What happens if you containerise it?

quick drill

A new teammate needs quicknotes running locally. With an image available, what do they need installed?

Remember

  • Ship the environment with the code: runtime, libraries and settings travel inside the image.
  • Shortcut: "Is it a difference in environment?" Yes means containers help; a plain code bug stays a bug.
  • Trap: containers share the host kernel and do not make wrong code right.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainMake the case for containers

quicknotes runs on your laptop with Python 3.12 but crashes on the team server, which has Python 3.8 and another app that needs 3.8. Explain how containers fix this, and name one problem containers would not fix.