The bakery app stopped on Saturday
A small bakery takes orders through a web app. On Saturday morning the orders stop arriving. The owner switches the laptop off and on again. Nothing changes.
The app is made of three small parts, each in its own container. One of them has stopped. In this lesson you learn to find the part that stopped and read why.
By the end of this lesson
Note
I can run and fix an app in a container.
Key words
| Word | What it means | Example |
|---|---|---|
| Image | a package holding a program and everything it needs | |
| Container | a running copy of an image | |
| Status | whether a container is running, stopped or unwell | Exited (1) |
| Log | the messages a program writes while it runs | |
| Restart | stop a container and start the same one again | |
| Volume | a folder kept outside a container, so it is saved |
The cells students fill in are left blank in this preview.
Before you start
Note
Press Start the lab on the bar at the top and wait until it says it is ready. Each Run button types its command into your lab terminal. Your lab is a private copy, so nothing you do here reaches anybody else.
An app is often several containers
An image is like a recipe. It never changes. A container is a running copy of an image, like a cake made from the recipe.
Your lab app has three containers. web shows a page, cache keeps a list of jobs and worker takes jobs from that list. The first command lists every container, running or not.
List every container
docker ps -aShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Worked example: reading the list
| Column | What it tells you | In your lab |
|---|---|---|
| IMAGE | the image it was made from | nginx for web, valkey for cache and worker |
| STATUS | running, stopped or unwell | Up (healthy) for two, Exited (1) for one |
| NAMES | the name you type in commands | web, cache, worker |
The cells students fill in are left blank in this preview.
Look inside a container that runs
docker exec runs one command inside a container that is running. It is how you look around without changing anything.
The next three Runs look at the two healthy parts. The first lists the processes inside web. The second asks web for its page. The third asks cache if it is alive.
List the processes inside web
docker exec web psShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask web for its page
curl -s http://webShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask cache if it is alive
docker exec cache valkey-cli pingShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
The log says why a program stopped
A program writes messages while it runs. Together they are its log. When a container stops, its last lines often say why.
So the order is always the same. Find the stopped container. Read its log. Fix the cause. Then restart it. Here is the log of the healthy cache, so you know what a good start looks like.
Read the cache's log
docker logs cacheShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Worked example: a till app that stopped
| Step | What you do | What you find |
|---|---|---|
| 1. Find it | docker ps -a | till-print shows Exited (1) |
| 2. Read why | docker logs till-print | cannot start, no PRINTER line in printer.conf |
| 3. Fix the cause | add the missing line to the settings file | the file now names the printer |
| 4. Start again | docker restart till-print | Up (healthy) |
The cells students fill in are left blank in this preview.
A common mistake
Warning
Many people think a restart fixes a stopped container. A restart runs the same program with the same settings, so it stops for the same reason. Read the log first and fix the cause. Restart only after that.
Make a file inside web
docker exec web touch /tmp/note.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Restart web
docker restart webShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Is the file still there?
docker exec web ls /tmpShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Going further: two kinds of stop
Exited (0) means a program finished its job and stopped on purpose. Any other number, such as Exited (1), means it stopped because something went wrong.
Change your needs_attention so that Exited (0) is left out. Add one test of your own that shows it works.