TOPIC 18/1916 MINNOT STARTED

Debug a container: logs, exec, inspect, port clashes and exit codes

Find out why a container stops at once or will not start, using logs, exec, inspect and the exit code, and fix a port clash.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: -up. The doctor reads the chart first, then listens, then looks up the file of details. If the patient has already left, only the chart and the file remain. A different problem is the door: two people cannot use the same door number at once.

The chart is the log. Listening is exec, and it only works while the patient is still there. The file is inspect. The door number is the host port.

Tom, a tester at Daily List, a to-do list app, finds a fault in a container that exits at once. Lily watches the with him.

What it is: This is a slice of Docker, the program that runs containers. A is the number left when the container stops, and a means your port is already taken. Exec into a running container is docker exec, and it works only while the main program is still running. Restarting with no new fact is the neighbour. It feels busy, and it does not explain the failure.

Why it matters: A broken Daily List test container wastes a whole (CI) run if Tom only restarts it. The log, the exit code and inspect turn "it will not work" into a cause he can say in the stand-up. A port clash is a one-line fix once he sees which number is taken.

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB A doctor reading a chart and examining a patient.

  1. Chart
  2. Listen
  3. Details
Doctor check-up

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The chart notesThe container logs
The patient already gone homeA stopped container
Listening to the patient in the roomExec into a running container
The record of the patient detailsThe inspect report

WHERE THIS PICTURE STOPS

  • A chart is written by nurses, but logs are written by the program itself.
  • A patient in the room can answer, and a stopped container cannot.
  • A check-up is one visit, but a bug may need more than one run.

HOOK

Chart first, then the patient.

TELL A FRIEND

Read the chart, listen, then look at the details.

OFTEN MIXED UP WITH Docker Compose: service names, ports, a named volume and exec. That topic uses compose, networks, volumes and exec when things work. This one finds the cause when a container will not start or keeps stopping.

PRACTISE AND KEEP

Sources for this topic — 4 sources
  1. Market practice

    docker container logs (Docker Docs, CLI reference) ↗ — Docker · Docker docs for container logs: logs fetches the output a container wrote, with options such as follow and tail

    Says docker logs fetches the output a container wrote, with options such as follow, tail, since and timestamps. Vendor documentation. Practitioner guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Running containers (Docker documentation) ↗ — Docker · Docker docs on running containers: 125 means Docker failed, 126 means the command could not be run, 127 means it was not found, and other codes come from the command

    The Docker page on running containers: exit code 125 means Docker itself failed, 126 means the command could not be run and 127 means it was not found. Any other code is the code of the command inside the container. · Checked 2026-10-31

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    Container exec and inspect (Docker documentation) ↗ — Docker · Docker docs on exec and inspect: exec runs only while the main process runs, and inspect prints container details

    The Docker pages on exec and inspect: exec runs a command only while the main process of the container is running. Inspect prints detailed information about a container, and a format option picks out one field. · Checked 2026-10-31

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Publishing and exposing ports (Docker documentation) ↗ — Docker · Docker guide on publishing ports: the host port comes first, and leaving it out lets Docker choose a free one

    The Docker guide on publishing ports: the publish option takes the host port first and the container port second. Leaving out the host port lets Docker choose one, which avoids clashes. The port command shows the mappings. · Checked 2026-10-31

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.