DEV Community

Chandrashekhar Kachawa
Chandrashekhar Kachawa

Posted on

Mastering Docker Commands: A Comprehensive Guide for Developers

Docker has become a must-have skill for developers and DevOps engineers. Whether you're deploying microservices, testing in isolated environments, or optimizing workflows, Docker makes it all easier.

But to truly leverage Dockerโ€™s power, you need to master its command-line interface (CLI).
This guide walks you through the most essential Docker commands, complete with usage details and real-world examples.


๐Ÿงฑ 1. Image Management Commands

Docker images are the blueprints for containers. These commands help you manage and manipulate them efficiently.

๐Ÿณ docker pull

Download an image from a registry (like Docker Hub).

Usage

docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Enter fullscreen mode Exit fullscreen mode

Example

docker pull ubuntu:latest
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ฆ docker images (or docker image ls)

List all local Docker images.

docker images
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”จ docker build

Build an image from a Dockerfile.

docker build -t my-app:1.0 .
Enter fullscreen mode Exit fullscreen mode

๐Ÿ—‘๏ธ docker rmi

Remove one or more images.

docker rmi my-app:1.0
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ docker push

Push an image to a registry.

docker push myusername/my-app:1.0
Enter fullscreen mode Exit fullscreen mode

๐Ÿงฉ 2. Container Management Commands

Containers are runnable instances of Docker images. Manage their lifecycle with these commands.

โ–ถ๏ธ docker run

Run a container from an image.

docker run -d -p 8080:80 --name my-nginx nginx
Enter fullscreen mode Exit fullscreen mode

๐Ÿงญ docker ps

List running containers.

docker ps
Enter fullscreen mode Exit fullscreen mode

To include stopped containers:

docker ps -a
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” docker start / docker stop / docker restart

Manage container state:

docker start my-nginx
docker stop my-nginx
docker restart my-nginx
Enter fullscreen mode Exit fullscreen mode

๐Ÿงน docker rm

Remove containers.

docker rm my-nginx
# Force remove
docker rm -f my-nginx
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’ฌ docker exec

Execute commands inside a running container.

docker exec -it my-nginx bash
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“œ docker logs

View container logs.

docker logs my-nginx
# Follow logs live
docker logs -f my-nginx
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ 3. Network Management Commands

Docker networks enable container communication.

๐ŸŒ docker network ls

List networks.

docker network ls
Enter fullscreen mode Exit fullscreen mode

๐Ÿงฑ docker network create

Create a custom network.

docker network create my-custom-network
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”— docker network connect / disconnect

Manage container network connections.

docker network connect my-custom-network my-nginx
docker network disconnect my-custom-network my-nginx
Enter fullscreen mode Exit fullscreen mode

โŒ docker network rm

Remove a network.

docker network rm my-custom-network
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’พ 4. Volume Management Commands

Docker volumes persist data between container restarts or removals.

๐Ÿ“š docker volume ls

List all volumes.

docker volume ls
Enter fullscreen mode Exit fullscreen mode

โž• docker volume create

Create a named volume.

docker volume create my-data
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” docker volume inspect

Inspect a volume.

docker volume inspect my-data
Enter fullscreen mode Exit fullscreen mode

๐Ÿงจ docker volume rm

Remove a volume.

docker volume rm my-data
Enter fullscreen mode Exit fullscreen mode

โš™๏ธ 5. System-Wide Commands

These commands give you visibility into Dockerโ€™s overall state and allow you to keep things tidy.

๐Ÿง  docker info

View Docker system information.

docker info
Enter fullscreen mode Exit fullscreen mode

๐Ÿงพ docker version

Check Docker version details.

docker version
Enter fullscreen mode Exit fullscreen mode

๐Ÿงผ docker system prune

Clean up unused containers, images, and networks.

docker system prune -a
Enter fullscreen mode Exit fullscreen mode

๐Ÿ Conclusion

By mastering these Docker commands, youโ€™ll be able to:

  • Manage containers and images efficiently
  • Simplify networking and data persistence
  • Keep your Docker environment clean and optimized

๐Ÿ’ก Pro tip: Experiment with Docker Compose next โ€” it lets you manage multi-container applications effortlessly.


๐Ÿ’ฌ Whatโ€™s your most-used Docker command? Drop it in the comments below!
If you found this guide helpful, consider following me for more DevOps & Cloud tips ๐Ÿš€

Top comments (0)