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

CommandDescription
docker build -t <name> .Build an image from a Dockerfile in the current directory.
docker imagesList 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

CommandDescription
docker run -d -p 8080:80 <image>Run a container in detached mode with port mapping.
docker psList running containers.
docker ps -aList 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> shOpen an interactive shell inside a running container.
docker inspect <container>View detailed configuration and state as JSON.

Volume & Network Commands

CommandDescription
docker volume create <name>Create a named volume for persistent data.
docker volume lsList volumes.
docker network create <name>Create a custom network so containers can communicate by name.
docker network lsList networks.

Docker Compose Commands

CommandDescription
docker compose up -dStart all services defined in docker-compose.yml in the background.
docker compose downStop and remove all services, networks, and default volumes.
docker compose logs -fStream logs from all services.
docker compose buildRebuild images defined in the compose file.

Cleanup Commands

CommandDescription
docker system pruneRemove unused containers, networks, and dangling images.
docker system prune -aRemove all unused images too, not just dangling ones.
docker container pruneRemove 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