Master Essential Docker Commands: A Quick Reference for Container Operations
This guide presents a concise, step‑by‑step reference of the most frequently used Docker commands for managing images, containers, troubleshooting, data volumes, networks, and system cleanup, and highlights five core commands that can resolve the majority of everyday container issues.
Image Operations
Pull an image from a registry: docker pull nginx:latest List local images: docker images Remove a local image: docker rmi nginx:latest Build a new image from a Dockerfile:
docker build -t myapp:1.0 .Container Operations
Run a container (most common usage): docker run -d -p 8080:80 --name mynginx nginx Common flags: -d – run in background -p – map host port to container port --name – assign a name to the container -v – mount a volume -e – set environment variables
List running containers: docker ps List all containers (including stopped): docker ps -a Stop a container: docker stop mynginx Start a stopped container: docker start mynginx Restart a container: docker restart mynginx Remove a container: docker rm mynginx Force‑remove a container:
docker rm -f mynginxContainer Troubleshooting
View container logs (follow mode): docker logs -f mynginx Enter a running container for interactive debugging: docker exec -it mynginx /bin/bash Enter an Alpine‑based container: docker exec -it mynginx /bin/sh Inspect detailed container information: docker inspect mynginx Show real‑time resource usage of containers:
docker statsData and Network
List Docker volumes: docker volume ls List Docker networks: docker network ls Inspect a specific network (e.g., bridge):
docker network inspect bridgeSystem Management
Clean up unused resources (images, containers, networks, volumes): docker system prune -a Export an image to a tar archive: docker save -o nginx.tar nginx Import an image from a tar archive: docker load -i nginx.tar Commit a running container as a new image:
docker commit mynginx mynginx:v2Five Core Commands
If you only remember five Docker commands, they are:
docker run docker ps docker logs -f docker exec -it docker system pruneThese commands can resolve roughly 80 % of common production issues related to containerized services.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
