Card 04/ 06

ExampleDifficulty: Intermediate1 min

Reading Why a Container Exited

You start a container and it is gone by the time you look for it. docker ps shows nothing, which is the least helpful thing it could say.

bash
$ docker run -d --name api my-api
3c8f0a1d5b62
$ docker ps
CONTAINER ID   IMAGE   STATUS   NAMES

docker ps lists what is running. A container that exited is still there, and -a is what shows it.

bash
$ docker ps -a --format '{{.Names}}\t{{.Status}}'
api	Exited (1) 6 seconds ago

Exit code 1, so the program decided to stop rather than being killed. Whatever it printed on the way out is still held against the container.

bash
$ docker logs api
Error: DATABASE_URL is not set

The container exiting is almost never the problem. It is the program inside reporting one, and docker logs is where it said so.