Docker Command Recipes & Dockerfile Solutions

Essential CLI recipes for everyday container management. Exec into containers with Bash, prune disk space, mount volumes, stream logs, write multi-stage builds, and master ENTRYPOINT vs CMD.

Containers & ExecSafe

How to Exec / SSH into a Running Docker Container with Bash

Open an interactive terminal shell session inside a live running Docker container to inspect files, debug processes, or test network connectivity.

docker exec -it <container-name> /bin/bash
Full step-by-step tutorial & options
Cleanup & PruneDestructive

How to Clean Up Docker Disk Space (Prune Containers, Images & Volumes)

Reclaim gigabytes of hard drive space by removing stopped containers, unused networks, dangling images, and build caches.

docker system prune -a --volumes
Full step-by-step tutorial & options
Containers & ExecReversible

How to Stop and Remove All Running Docker Containers

Instantly stop all active containers and optionally remove them with a single command.

docker stop $(docker ps -q)
Full step-by-step tutorial & options
Volumes & StorageSafe

How to Copy Files Between a Docker Container and Host Machine

Copy files or directories between a Docker container and your local host file system without creating a volume mount.

docker cp <container>:/path/in/container /path/on/host
Full step-by-step tutorial & options
Dockerfile DirectivesSafe

ENTRYPOINT vs CMD in Dockerfile: Differences and Best Practices

Understand the fundamental differences between ENTRYPOINT and CMD directives and how to combine them for flexible container CLIs.

ENTRYPOINT ["node", "server.js"] CMD ["--port", "3000"]
Full step-by-step tutorial & options
Containers & ExecSafe

How to View and Follow Docker Container Logs in Real Time

Inspect stdout and stderr output from containers with timestamps, tail line limits, and live streaming.

docker logs -f --tail 100 <container-name>
Full step-by-step tutorial & options
Dockerfile DirectivesSafe

COPY vs ADD in Dockerfile: Which Should You Use?

Best practices for copying files into Docker images. Why COPY is almost always preferred over ADD.

COPY package.json package-lock.json ./
Full step-by-step tutorial & options
Networks & PortsSafe

How to Find a Docker Container IP Address and Network Info

Extract the private bridge or overlay IP address of a running container using docker inspect formatting templates.

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container>
Full step-by-step tutorial & options
Volumes & StorageSafe

How to Mount Volumes and Bind Mounts in Docker

Persist database files and hot-reload local source code inside containers using named volumes and host bind mounts.

docker run -v my_volume:/var/lib/data -v $(pwd):/app -p 3000:3000 my-image
Full step-by-step tutorial & options
Images & BuildSafe

How to Create Docker Multi-Stage Builds to Reduce Image Size

Shrink production Docker image sizes from 1.5GB down to 50MB by separating heavy build dependencies from the minimal production runtime.

FROM node:20-alpine AS builder ... FROM node:20-alpine AS runner COPY --from=builder /app/dist ./dist
Full step-by-step tutorial & options