TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

All concepts ยท infrastructure ยท devops ยท containers

Docker and containers

Packaging an app with everything it needs (runtime, libraries, config) into an image that runs the same everywhere as an isolated container sharing the host's kernel.

9 min3 animations

๐Ÿ–จ๏ธ Cheat sheet

Loose parts

You build something in your workshop and it works perfectly, with your tools and your parts. Then you post the loose parts to two ships. One has different tools on board; the other is missing a part you didn't know you needed. Every ship is a surprise.

Environment drift

An application depends on much more than its code: a language runtime of a particular version, OS libraries, environment variables, config files. Install those by hand on each server and they drift: test has Java 17, production is missing a font library, a laptop has an env var nobody wrote down. Result: "works on my machine".

It works on my machine3 steps
๐Ÿง‘โ€๐Ÿ”งYour workshop๐ŸšขShip Aโ›ด๏ธShip B
Press play and watch it happen!

One standard box

So you pack the thing and everything it needs into a standard shipping container, and leave it at the container yard. Any ship can collect an identical copy, and every ship carries it the same way.

Images and containers

A Dockerfile describes how to build an image: a read-only stack of layers.

1FROM eclipse-temurin:21-jre2COPY target/app.jar /app/app.jar3EXPOSE 80804ENTRYPOINT ["java", "-jar", "/app/app.jar"]

docker build -t shop/orders:1.4 . builds it, docker push uploads it to a registry, and docker run starts a container, a running instance. The same image runs on a laptop, in CI and in production. Layers are cached and shared, so rebuilding after a code change only redoes the last layers.

Pack it in a container3 steps
๐Ÿง‘โ€๐Ÿ”งYour workshop๐Ÿ—๏ธ Container yard๐ŸšขShip Aโ›ด๏ธShip B
Press play and watch it happen!

Many boxes, one ship

A ship carries many boxes. None can see into the others, each has a weight limit, and they all share one hull, which is why they're so much lighter than sending a ship each.

Containers versus virtual machines

A container is an isolated process, not a computer. Linux namespaces give it its own filesystem, process ids and network; cgroups limit its CPU and memory. Every container shares the host's kernel, so it starts in milliseconds and uses megabytes, where a VM boots a whole OS. The trade-off is weaker isolation than a VM.

Containers are disposable: keep data in volumes or databases, not inside the container.

Many boxes on one ship3 steps
๐Ÿšข One ship๐Ÿ“ฆBox 1๐Ÿ“ฆBox 2๐Ÿ“ฆBox 3๐ŸšขThe ship's hull
Press play and watch it happen!

๐Ÿงฉ Quick quiz

Quick quiz! 3 questions about Docker and containers, told the same way as the story.
  1. Why did the loose parts work in your workshop but not on every ship?
  2. What goes into the standard shipping container?
  3. Why are many boxes on one ship lighter than a ship each?
Answer every question to check.Passing marks Docker and containers as done.
Got the hang of Docker and containers? Mark it as done, and your paths show how far youโ€™ve got.

Saved in this browser.

๐Ÿš€ Shipping to productionStep 4 of 10

โ† Previous on the path๐Ÿชด Infrastructure as code (Terraform)Next on the path โ†’โš“ Kubernetes

๐Ÿ‘‰ Read next

  • ๐Ÿš›Amazon ECS, Fargate and EKSA port with working berths for containers: bring your own lorries or rent one by the trip.
  • โš“KubernetesA harbour master who keeps the right number of ships docked and replaces any that sink.