Skip to main content
Cloud & DevOps

Docker & Docker Compose

Essential

Production container lifecycle, multi-stage builds, Docker Compose orchestration, volume management, and system pruning.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Docker & Docker Compose Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (19 Total Commands).

19+ Verified Recipes
Container Execution-d, -p, --name, --restart
docker run -d --name web -p 8080:80 --restart unless-stopped nginx:alpine

Run container in background detached mode with port forwarding and restart policy.

Inspection-a, --format
docker ps -a --format "table {{.ID}} {{.Names}} {{.Status}} {{.Ports}}"

List all running and stopped containers in a clean formatted table.

Shell Access-it
docker exec -it web /bin/sh

Open an interactive terminal shell session inside a running container.

Logs & Diagnostics-f, --tail
docker logs -f --tail 100 web

Stream live container output logs starting with the last 100 lines.

Image Build-t, -f
docker build -t myapp:v1.0 -f Dockerfile .

Build an optimized container image from a local Dockerfile with a version tag.

Docker Composeup -d --build
docker compose up -d --build

Build, recreate, and start all microservices defined in docker-compose.yml in background.

Docker Composedown -v
docker compose down -v

Stop and remove all containers, networks, and named persistent storage volumes.

Storage & Volumesvolume create, ls
docker volume create pgdata && docker volume ls

Create and list managed persistent storage volumes detached from container lifecycle.

Networkingnetwork create --driver
docker network create --driver bridge app-net

Create an isolated user-defined bridge network for internal DNS resolution.

Resource Monitoring--no-stream
docker stats --no-stream

Display a snapshot of CPU, memory, network I/O, and disk usage across running containers.

File Copycp <container>:<path> <dest>
docker cp web:/etc/nginx/nginx.conf ./nginx.conf

Copy configuration files or assets between a container and the local host filesystem.

Maintenance & Cleanup-af, --volumes
docker system prune -af --volumes

Reclaim disk space by purging all stopped containers, dangling images, and unused volumes.

Multi-Architecture Builds--platform --push
docker buildx build --platform linux/amd64,linux/arm64 -t username/app:v1.0 --push .

Compile multi-architecture container images supporting both x86_64 servers and Apple Silicon / ARM64 AWS Graviton nodes.

Resource Monitoring--no-stream --format
docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}'

Print real-time CPU, RAM, and network I/O consumption across all running containers in clean tabular format.

Container File Copycp <src> <dest>
docker cp my-container:/var/log/nginx/error.log ./local-error.log

Copy files or directories between a running container and the local host filesystem without SSH access.

Process Inspectiontop <container>
docker top my-container aux

Display all active running processes inside a specific container along with host PIDs.

Network Inspection--format
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-container

Extract the internal bridge IP address assigned to a running container.

Volume Backup--rm -v
docker run --rm -v db_data:/data -v $(pwd):/backup alpine tar czf /backup/db_backup.tar.gz -C /data .

Create a compressed tarball backup of a named Docker persistent volume using an ephemeral helper container.

Compose Scale--scale <service>=<n>
docker compose up -d --scale worker=4

Horizontally scale the background worker service to 4 parallel container replicas in Docker Compose.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Docker & Docker Compose: Command Groups & Quick Index

19 indexed entries across 17 sections
Container Execution1 items
Inspection1 items
Shell Access1 items
Logs & Diagnostics1 items
Image Build1 items
Docker Compose2 items
Storage & Volumes1 items
Networking1 items
Resource Monitoring2 items
File Copy1 items
Maintenance & Cleanup1 items
Multi-Architecture Builds1 items
Container File Copy1 items
Process Inspection1 items
Network Inspection1 items
Volume Backup1 items
Compose Scale1 items

Highlighted Flags & Syntax Examples in Docker & Docker Compose

docker run -d --name web -p 8080:80 --restart unless-stopped nginx:alpine

Run container in background detached mode with port forwarding and restart policy.

Flags: -d, -p, --name, --restart
docker ps -a --format "table {{.ID}} {{.Names}} {{.Status}} {{.Ports}}"

List all running and stopped containers in a clean formatted table.

Flags: -a, --format
docker exec -it web /bin/sh

Open an interactive terminal shell session inside a running container.

Flags: -it
docker logs -f --tail 100 web

Stream live container output logs starting with the last 100 lines.

Flags: -f, --tail

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Docker & Docker Compose.

What is the difference between ADD and COPY in a Dockerfile?

COPY is preferred for local files and directories as it performs straightforward file copying. ADD can automatically extract tar archives and fetch files from remote URLs, which can introduce unpredictable build cache behavior.

How do multi-stage builds reduce container image size?

Multi-stage builds allow you to use heavy SDK images for compiling binaries and then copy only the compiled executable into a minimal runtime base (such as distroless or alpine), stripping compilers, caches, and devDependencies.

What is the difference between ENTRYPOINT and CMD?

ENTRYPOINT specifies the immutable executable run when the container starts. CMD provides default arguments to the ENTRYPOINT which can be easily overridden by passing CLI arguments to docker run.

What is the difference between Docker CMD and ENTRYPOINT in Dockerfiles?

ENTRYPOINT specifies the immutable binary or executable that runs when the container starts (e.g. ENTRYPOINT ["nginx"]). CMD provides default arguments to that executable (CMD ["-g", "daemon off;"]). Arguments passed to docker run override CMD completely, but are appended to ENTRYPOINT.

Why should production containers never run as root?

By default, container root (UID 0) maps directly to host root (UID 0). A container breakout vulnerability (such as CVE-2024-21626 in runc) gives an attacker full root control over the host operating system. Always create an unprivileged user (USER node or USER appuser) in your Dockerfile.

How does Docker layer caching work and how can I optimize it?

Docker executes instructions from top to bottom. If an instruction (like COPY package.json) has not changed, Docker reuses the cached layer. Placing static dependencies (COPY package*.json && npm ci) BEFORE dynamic source code (COPY . .) ensures Docker skips npm installs when only source files change, cutting build times from minutes to seconds.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets