DEV Community

Yash Sonawane
Yash Sonawane

Posted on

๐Ÿ›ณ๏ธ Docker Series: Episode 5 โ€” Docker CLI Cheat Sheet: 15 Commands Youโ€™ll Actually Use

๐ŸŽฌ "You've built your first Docker image โ€” high five! ๐Ÿ–๏ธ Now it's time to command Docker like a boss. No more googling basic commands. Hereโ€™s your go-to cheat sheet, packed with real examples."


๐Ÿง  Why Learn Docker CLI?

GUI tools are fine, but the real power of Docker lies in the terminal. If you want to:

  • Automate workflows
  • Debug faster
  • Build better CI/CD pipelines

Then mastering the Docker CLI is non-negotiable. Letโ€™s dive into the commands that matter.


๐Ÿš€ Image Commands

๐Ÿ“ฆ 1. docker pull

Download an image from Docker Hub.

docker pull node:18
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ฆ 2. docker images

List all downloaded images.

docker images
Enter fullscreen mode Exit fullscreen mode

๐Ÿงน 3. docker rmi

Remove an image.

docker rmi node:18
Enter fullscreen mode Exit fullscreen mode

๐Ÿงช Container Commands

๐Ÿƒ 4. docker run

Run a container from an image.

docker run -d -p 3000:3000 my-node-app
Enter fullscreen mode Exit fullscreen mode

๐Ÿงญ 5. docker ps

List running containers.

docker ps
Enter fullscreen mode Exit fullscreen mode

๐Ÿ‘๏ธ 6. docker ps -a

List all containers (including stopped ones).

docker ps -a
Enter fullscreen mode Exit fullscreen mode

๐Ÿ›‘ 7. docker stop

Stop a running container.

docker stop <container_id>
Enter fullscreen mode Exit fullscreen mode

โŒ 8. docker rm

Remove a container.

docker rm <container_id>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Debugging & Logs

๐Ÿ“œ 9. docker logs

View logs from a container.

docker logs <container_id>
Enter fullscreen mode Exit fullscreen mode

๐Ÿš 10. docker exec

Run a command inside a running container.

docker exec -it <container_id> bash
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”Ž 11. docker inspect

View detailed info (network, config, volumes, etc.).

docker inspect <container_id>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ› ๏ธ Image Building & Tagging

๐Ÿงฑ 12. docker build

Build a Docker image from a Dockerfile.

docker build -t my-node-app .
Enter fullscreen mode Exit fullscreen mode

๐Ÿท๏ธ 13. docker tag

Tag an image for pushing to Docker Hub.

docker tag my-node-app yashsonawane/my-node-app:latest
Enter fullscreen mode Exit fullscreen mode

โ˜๏ธ 14. docker push

Push an image to Docker Hub.

docker push yashsonawane/my-node-app:latest
Enter fullscreen mode Exit fullscreen mode

๐Ÿงน Cleanup Commands

๐Ÿงฝ 15. docker system prune

Remove all unused data โ€” WARNING: this will free space aggressively.

docker system prune
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“Œ Pro Tips

  • Use -it for interactive terminals (bash, sh, etc.)
  • Use container/image names instead of long IDs
  • Keep a .dockerignore file to reduce image size

๐Ÿง  Whatโ€™s Next?

In Episode 6, weโ€™ll cover:

  • Docker Volumes: Why data disappears when you stop containers
  • How to persist data like a pro
  • Real use cases (MySQL, logs, etc.)

๐Ÿ’ฌ Over to You

Whatโ€™s your favorite Docker command?
What confused you the most when using the CLI for the first time?

Drop it in the comments โ€” letโ€™s learn from each other!

โค๏ธ If this cheat sheet helped, give it a like, bookmark it, or share it with your fellow devs.

๐ŸŽฌ Next: โ€œDocker Volumes โ€” The Secret to Saving Your Dataโ€

Top comments (0)