Docker
20 Essential Docker Commands Every Developer Must Know
By Utility Zone ยท 2025-11-03T05:51:28.379333
Docker is one of the most powerful tools in modern software development. Mastering its core commands helps you build, ship, and run applications efficiently. In this guide, weโll explore the 20 essential Docker commands every developer should know โ with explanations and examples.
๐งฉ 1. docker --version
Purpose: Check the installed Docker version.
docker --version
Displays the version of Docker installed on your machine. Useful for troubleshooting and verifying setup.
โ๏ธ 2. docker pull
Purpose: Download an image from Docker Hub or a private registry.
docker pull nginx
Pulls the latest nginx image from Docker Hub.
๐ฆ 3. docker images
Purpose: List all images available on your system.
docker images
Shows repository name, tag, image ID, size, and creation date.
๐ 4. docker run
Purpose: Create and start a container from an image.
docker run -d -p 8080:80 nginx
Runs an Nginx container in detached mode (-d) and maps port 8080 on the host to port 80 in the container.
๐งฑ 5. docker ps
Purpose: Display running containers.
docker ps
Use docker ps -a to show all containers, including stopped ones.
๐ 6. docker stop
Purpose: Stop one or more running containers.
docker stop <container_id>
Gracefully stops the specified container.
๐๏ธ 7. docker rm
Purpose: Remove a stopped container.
docker rm <container_id>
Cleans up unused containers to free space.
๐งน 8. docker rmi
Purpose: Remove one or more images.
docker rmi <image_id>
Deletes an image from the local system.
๐งฐ 9. docker exec
Purpose: Execute commands inside a running container.
docker exec -it <container_id> /bin/bash
Opens an interactive bash shell inside the container.
๐ต๏ธ 10. docker logs
Purpose: View logs of a container.
docker logs <container_id>
Useful for debugging running or crashed containers.
๐ 11. docker inspect
Purpose: Display detailed information about Docker objects.
docker inspect <container_id>
Shows metadata including environment variables, network settings, and mount points.
๐ 12. docker cp
Purpose: Copy files between host and container.
docker cp <container_id>:/usr/src/app/file.txt ./file.txt
Allows easy transfer of files without volume mounting.
๐งฎ 13. docker stats
Purpose: Display real-time resource usage of containers.
docker stats
Shows CPU, memory, network, and disk I/O metrics.
๐งพ 14. docker commit
Purpose: Create a new image from a containerโs current state.
docker commit <container_id> my-custom-image
Captures container changes into a new reusable image.
๐ฆ 15. docker build
Purpose: Build an image from a Dockerfile.
docker build -t myapp:latest .
Reads the Dockerfile in the current directory and creates a new image tagged myapp:latest.
โก 16. docker network ls
Purpose: List all Docker networks.
docker network ls
Helps in managing container communication and isolation.
๐ 17. docker network inspect
Purpose: View network configuration details.
docker network inspect bridge
Displays connected containers and their IP addresses.
๐พ 18. docker volume ls
Purpose: List all Docker volumes.
docker volume ls
Shows all persistent storage volumes on the host.
๐งจ 19. docker system prune
Purpose: Remove all unused data โ containers, images, networks, and cache.
docker system prune -a
Frees up significant disk space by cleaning up dangling resources.
๐ง 20. docker-compose up
Purpose: Start services defined in a docker-compose.yml file.
docker-compose up -d
Brings up multiple containers (backend, frontend, database, etc.) in one command.
๐ฏ Bonus: Handy One-Liners
- Stop all running containers:
docker stop $(docker ps -q) - Remove all containers:
docker rm $(docker ps -aq) - Remove all images:
docker rmi $(docker images -q)
โ Conclusion
Knowing these Docker commands gives you control over your container lifecycle โ from building and running to debugging and cleaning up. Keep this list handy as your quick reference while developing or deploying containerized applications.
Author: UtilityZone Editorial Team
Published on: 2025
Category: DevOps / Docker Tutorials