Containers
Docker Backend Debugging Cheatsheet
Containers
List running containers
Use this to see only containers that are currently running.
Command
docker psList all containers
Use this to include stopped containers in the result.
Command
docker ps -aLogs
Show container logs
Use this to inspect recent logs for a container.
Command
docker logs container-nameFollow live logs
Use this while reproducing an issue locally.
Command
docker logs -f container-nameShell Access
Open a shell with sh
Use this for minimal containers that do not include bash.
Command
docker exec -it container-name shOpen a shell with bash
Use this when the image includes bash.
Command
docker exec -it container-name bashImages
List local images
Use this to see available images and their sizes.
Command
docker imagesRemove an image
Use this to delete an image that is no longer needed.
Command
docker rmi image-idBuild 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-nameStop And Remove
Stop a running container
Use this before removing or recreating a container.
Command
docker stop container-nameRemove a stopped container
Use this to clean up a container after it is no longer needed.
Command
docker rm container-nameCleanup
Remove unused Docker resources
Use this carefully to clean unused containers, networks, images, and cache.
Command
docker system pruneDebug Checklist
- Confirm the container is running.
- Check port mapping.
- Read application logs.
- Check environment variables.
- Verify network connectivity.