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