⚡ 100% In-Browser & Private: Your data never leaves your computer. Powered by Cloudflare Edge CDN.
ProWebTools PRO
Developer & SEO Utilities
DevOps Matrix

Docker & Docker Compose Cheat Sheet

Production Docker CLI reference: container creation, logs tailing, exec sh, compose commands, and disk pruning.

Container Lifecycle (5 commands)

Container Lifecycle
docker run -d -p 8080:80 --name my-app nginx:alpine

Runs an Nginx container in detached (-d) background mode on port 8080.

PRO TIP Maps host port 8080 to container port 80.
Container Lifecycle
docker ps

Lists all currently running Docker containers.

PRO TIP Use docker ps -a to inspect stopped or exited containers.
Container Lifecycle
docker stop <container-id-or-name>

Gracefully sends SIGTERM followed by SIGKILL to stop container execution.

PRO TIP Allows application up to 10 seconds to finish active connections.
Container Lifecycle
docker start <container-id-or-name>

Starts an existing, stopped container without recreating its configuration.

PRO TIP Preserves container state and internal filesystem modifications.
Container Lifecycle
docker rm -f <container-id-or-name>

Forcefully removes a container instance from your local disk.

PRO TIP Combine with docker stop to safely clean up staging instances.

Images & Registry (4 commands)

Images & Registry
docker images

Lists all Docker images locally cached on the system.

PRO TIP Displays Image ID, repository, tag, and storage footprint.
Images & Registry
docker pull node:20-alpine

Downloads a target image from Docker Hub without launching a container.

PRO TIP Alpine-based images drastically minimize image size for production.
Images & Registry
docker build -t prowebtools/api:v1 .

Builds a Docker image from a Dockerfile in the current directory (.).

PRO TIP Use -t to tag your image with a memorable name and version tag.
Images & Registry
docker rmi <image-id-or-name>

Removes an image from local storage.

PRO TIP Fails if a running or stopped container is still referencing it.

Debugging & Inspection (4 commands)

Debugging & Inspection
docker logs -f --tail 100 <container-name>

Follows (-f) container stdout and stderr logs starting from last 100 lines.

PRO TIP Essential command for troubleshooting server crashes in production.
Debugging & Inspection
docker exec -it <container-name> sh

Opens an interactive (-it) shell inside a running container.

PRO TIP Use bash instead of sh if the container image includes bash.
Debugging & Inspection
docker stats

Streams real-time CPU, RAM, network, and disk I/O metrics across containers.

PRO TIP Helps identify resource bottlenecks and memory leaks.
Debugging & Inspection
docker inspect <container-name>

Dumps complete low-level JSON configuration including network IP addresses.

PRO TIP Use jq or grep to extract specific IP address fields.

Docker Compose (4 commands)

Docker Compose
docker compose up -d

Builds, creates, and starts all services declared in docker-compose.yml.

PRO TIP Runs multi-container microservice stacks with a single command.
Docker Compose
docker compose down -v

Stops and removes containers, default networks, and named volumes (-v).

PRO TIP Use -v with caution as it deletes persistent database volumes.
Docker Compose
docker compose ps

Lists all services managed by the current directory's compose file.

PRO TIP Shows service status and mapped exposed ports.
Docker Compose
docker compose logs -f <service-name>

Follows log streams for a specific service (e.g. web, db, redis).

PRO TIP Omitting the service name streams merged logs from all services.

Disk Cleanup (2 commands)

Disk Cleanup
docker system prune -af --volumes

Comprehensive cleanup: deletes stopped containers, unused networks, and dangling images.

PRO TIP Can free dozens of gigabytes of disk space on development workstations.
Disk Cleanup
docker image prune -a

Removes all images not currently referenced by at least one container.

PRO TIP Frees cached layer builds in local developer registries.