How to View Docker Logs and Troubleshoot Containers

Developer using a laptop while managing Docker containers from the command line

When a Docker container fails, start with its output and state. The usual sequence is docker ps -a, docker logs, and docker inspect. This gives you evidence before you restart or delete anything.

Find the container state

docker ps -a

Look for Exited, the exit code, and how long ago the process stopped. A container that repeatedly exits may have a configuration, dependency, or application error.

Read the logs

docker logs my-container
docker logs --tail 100 my-container
docker logs -f my-container

The first command prints available output. --tail 100 limits the result, while -f follows new lines as they arrive. Press Ctrl+C to stop following logs.

Docker logs normally show the process’s standard output and error streams. If an application writes only to a file inside the container, its output may not appear here.

Check the exit code and restart count

docker inspect --format '{{.State.Status}} {{.State.ExitCode}} {{.RestartCount}}' my-container

This prints the current status, last exit code, and restart count. Run it in a shell that supports single quotes; in PowerShell, double-quote handling may require escaping.

Inspect configuration

docker inspect my-container

Review the image, command, environment variables, mounts, networks, and port bindings. A missing environment variable or incorrect mount path is a common cause of startup failures.

Test a running container

docker exec -it my-container sh

This opens a shell if the image includes sh. Use it to test files, DNS, or application configuration. Exit the shell with exit.

Compose troubleshooting

docker compose ps
docker compose logs --tail 100
docker compose config

Run these commands from the Compose project directory. They show service state, recent logs, and the fully resolved configuration.

If logs are empty

  • The process may log to a file instead of standard output.
  • The container may never have started; inspect its state and events.
  • A different logging driver may send output elsewhere.
  • The Docker daemon itself may need troubleshooting.

Next steps

Once you identify the cause, fix the configuration and recreate only what is necessary. Docker’s logging documentation explains how container output is collected.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top