When a container will not start, keeps restarting, or behaves oddly, guessing wastes time. There is a repeatable order to work through, and it resolves most problems quickly. This node lays out the workflow; the next ones cover each tool in detail.
docker ps -a. Is the container up, exited, or restarting? Note the
exit code in the status - it is your first clue.docker logs. Most failures announce
themselves here: a missing environment variable, a config error, a
failed connection. This solves the majority of cases on its own.docker inspect to check the environment variables, mounts,
networks, and command it actually got - often different from what
you intended.docker exec a shell and look around - check files, test a network
call, run the command by hand.docker stats shows live memory and CPU use. A container hitting a
memory limit gets killed with exit code 137.The order is deliberate: each step costs a little more effort than the last, and the cheap early steps solve most problems. Checking status and logs takes seconds and answers the common cases. Only escalate to inspecting, shelling in, and watching resources when the simple checks come up empty.
The tempting move when a container misbehaves is to restart it and hope. Sometimes that clears a transient glitch, but it also destroys the state that would tell you what went wrong, so the problem often returns with no new information. Diagnose first - read the status and logs - then restart deliberately if the evidence points that way.