Card 04/ 06
All 6 cards
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.
$ docker run -d --name api my-api
3c8f0a1d5b62
$ docker ps
CONTAINER ID IMAGE STATUS NAMESdocker ps lists what is running. A container that exited is still there, and -a is what shows it.
$ docker ps -a --format '{{.Names}}\t{{.Status}}'
api Exited (1) 6 seconds agoExit 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.
$ docker logs api
Error: DATABASE_URL is not setThe container exiting is almost never the problem. It is the program inside reporting one, and docker logs is where it said so.