Commands
Top Docker Commands You Should Know
Whether you're building images, running containers, or debugging a stack, these are the Docker CLI commands you'll reach for most often. They're grouped by what you're working with — images, containers, volumes, networks, and Docker Compose.
Image Commands
| Command | Description |
docker build -t <name> . | Build an image from a Dockerfile in the current directory. |
docker images | List all local images. |
docker pull <image> | Download an image from a registry (e.g., Docker Hub). |
docker push <image> | Upload an image to a registry. |
docker rmi <image> | Remove a local image. |
docker tag <src> <target> | Create a new tag for an existing image. |
Container Commands
| Command | Description |
docker run -d -p 8080:80 <image> | Run a container in detached mode with port mapping. |
docker ps | List running containers. |
docker ps -a | List all containers, including stopped ones. |
docker stop <container> | Gracefully stop a running container. |
docker start <container> | Start a stopped container. |
docker restart <container> | Restart a container. |
docker rm <container> | Remove a stopped container. |
docker logs -f <container> | Stream logs from a container. |
docker exec -it <container> sh | Open an interactive shell inside a running container. |
docker inspect <container> | View detailed configuration and state as JSON. |
Volume & Network Commands
| Command | Description |
docker volume create <name> | Create a named volume for persistent data. |
docker volume ls | List volumes. |
docker network create <name> | Create a custom network so containers can communicate by name. |
docker network ls | List networks. |
Docker Compose Commands
| Command | Description |
docker compose up -d | Start all services defined in docker-compose.yml in the background. |
docker compose down | Stop and remove all services, networks, and default volumes. |
docker compose logs -f | Stream logs from all services. |
docker compose build | Rebuild images defined in the compose file. |
Cleanup Commands
| Command | Description |
docker system prune | Remove unused containers, networks, and dangling images. |
docker system prune -a | Remove all unused images too, not just dangling ones. |
docker container prune | Remove all stopped containers. |
Key Takeaway: You don't need to memorize every Docker flag — focus on the core lifecycle commands (build, run, ps, stop, logs, exec) and Compose commands first. The rest become second nature with daily use.
Ready to master Docker?
Build, ship, and run containerized applications with confidence. Learn Docker and Kubernetes from industry experts with hands-on projects.
Explore Course