Master Docker: The Complete Command Cheat Sheet for Images, Containers, Volumes, and Networks
This guide provides a comprehensive, step‑by‑step reference of Docker CLI commands covering image management, container lifecycle, debugging, volume handling, network configuration, import/export operations, and system maintenance, complete with usage examples and key options.
Docker Image Management Commands
1. List local images docker images Displays all images stored locally.
2. Pull an image docker pull nginx Downloads the latest nginx image from Docker Hub. To pull a specific tag, append :tag (e.g., docker pull mysql:8.0).
3. Remove an image docker rmi nginx Deletes the specified image; add -f to force removal.
4. Search for images docker search redis Searches Docker Hub for images matching the keyword.
5. Build an image docker build -t myapp:1.0 . Builds an image from a Dockerfile in the current directory, tagging it as myapp:1.0.
-t : specify image name and tag
. : path to the
DockerfileDocker Container Management Commands
6. Run a container docker run -d -p 80:80 --name mynginx nginx -d : run in background
-p : map host port to container port
--name : assign a name to the container
7. List running containers docker ps 8. List all containers (including stopped) docker ps -a 9. Start a stopped container docker start container_id 10. Stop a running container docker stop container_id 11. Restart a container docker restart container_id 12. Remove a container docker rm container_id Use -f to force removal of a running container.
Container Debugging Commands
13. Execute a command inside a container docker exec -it container_id /bin/bash -i : interactive
-t : allocate a pseudo‑TTY
14. View container logs docker logs container_id Use -f to follow logs in real time.
15. Inspect container details docker inspect container_id Outputs detailed JSON information about the container.
Volume Management
16. Create a volume docker volume create mydata 17. List volumes docker volume ls 18. Remove a volume
docker volume rm mydataNetwork Management
19. List networks docker network ls 20. Create a network docker network create mynet 21. Inspect a network
docker network inspect bridgeImage and Container Import/Export
22. Export a container to a tar archive docker export container_id > container.tar 23. Import a tar archive as an image docker import container.tar myimage:1.0 24. Save an image to a tar file docker save nginx > nginx.tar 25. Load an image from a tar file
docker load < nginx.tarDocker System Management Commands
26. Show Docker version docker version 27. Show system information docker info 28. Prune unused resources docker system prune -a Removes stopped containers, unused images, and unused networks.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
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.
