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]
Example
docker pull ubuntu:latest
📦 docker images (or docker image ls)
List all local Docker images.
docker images
🔨 docker build
Build an image from a Dockerfile.
docker build -t my-app:1.0 .
🗑️ docker rmi
Remove one or more images.
docker rmi my-app:1.0
🚀 docker push
Push an image to a registry.
docker push myusername/my-app:1.0
🧩 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
🧭 docker ps
List running containers.
docker ps
To include stopped containers:
docker ps -a
🔁 docker start / docker stop / docker restart
Manage container state:
docker start my-nginx
docker stop my-nginx
docker restart my-nginx
🧹 docker rm
Remove containers.
docker rm my-nginx
# Force remove
docker rm -f my-nginx
💬 docker exec
Execute commands inside a running container.
docker exec -it my-nginx bash
📜 docker logs
View container logs.
docker logs my-nginx
# Follow logs live
docker logs -f my-nginx
🌐 3. Network Management Commands
Docker networks enable container communication.
🌍 docker network ls
List networks.
docker network ls
🧱 docker network create
Create a custom network.
docker network create my-custom-network
🔗 docker network connect / disconnect
Manage container network connections.
docker network connect my-custom-network my-nginx
docker network disconnect my-custom-network my-nginx
❌ docker network rm
Remove a network.
docker network rm my-custom-network
💾 4. Volume Management Commands
Docker volumes persist data between container restarts or removals.
📚 docker volume ls
List all volumes.
docker volume ls
➕ docker volume create
Create a named volume.
docker volume create my-data
🔍 docker volume inspect
Inspect a volume.
docker volume inspect my-data
🧨 docker volume rm
Remove a volume.
docker volume rm my-data
⚙️ 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
🧾 docker version
Check Docker version details.
docker version
🧼 docker system prune
Clean up unused containers, images, and networks.
docker system prune -a
🏁 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 (2)
I use the
docker exec -it [container] basha lot, but if you're using Docker Desktop, it's possible to accomplish much the same thing by clicking on the container and switching between the Files and Exec tabs, although it's not as efficient.That's true
however i just focused on commands so that people having better understanding how to do it without docker desktop
they don't usually install GUI on servers