Back to cheatsheets

Containers

Docker Backend Debugging Cheatsheet

Containers

List running containers

Use this to see only containers that are currently running.

Command
docker ps

List all containers

Use this to include stopped containers in the result.

Command
docker ps -a

Logs

Show container logs

Use this to inspect recent logs for a container.

Command
docker logs container-name

Follow live logs

Use this while reproducing an issue locally.

Command
docker logs -f container-name

Shell Access

Open a shell with sh

Use this for minimal containers that do not include bash.

Command
docker exec -it container-name sh

Open a shell with bash

Use this when the image includes bash.

Command
docker exec -it container-name bash

Images

List local images

Use this to see available images and their sizes.

Command
docker images

Remove an image

Use this to delete an image that is no longer needed.

Command
docker rmi image-id

Build And Run

Build an image

Use this to create a local image from the Dockerfile in the current folder.

Command
docker build -t app-name .

Run an image with a port mapping

Use this to expose a container port on your local machine.

Command
docker run -p 3000:3000 app-name

Stop And Remove

Stop a running container

Use this before removing or recreating a container.

Command
docker stop container-name

Remove a stopped container

Use this to clean up a container after it is no longer needed.

Command
docker rm container-name

Cleanup

Remove unused Docker resources

Use this carefully to clean unused containers, networks, images, and cache.

Command
docker system prune

Debug Checklist

  • Confirm the container is running.
  • Check port mapping.
  • Read application logs.
  • Check environment variables.
  • Verify network connectivity.