Docker is a tool that almost every developer encounters at some point. However, unless you use it daily, its commands can become hazy over time. It's easy to forget all but a few frequently used commands.
I often find myself looking up official documentation or searching online whenever this happens. To streamline that repetitive process, I've compiled this cheatsheet of frequently used Docker commands, organized simply and clearly.
It's designed to be a quick reference, containing only the essentials, ready whenever you need it. 😊

1. Image-Related Commands
| Command | Description |
|---|---|
docker build -t <name>:<tag> . |
Build an image from a Dockerfile in the current directory |
docker images |
List local images |
docker rmi <imageID> |
Delete an image |
docker pull <image> |
Pull an image from a remote repository |
docker push <image> |
Push an image to a repository (requires login) |
2. Container-Related Commands
| Command | Description |
|---|---|
docker run -d --name <name> -p 8000:8000 <image> |
Run a container in the background |
docker ps |
List currently running containers |
docker ps -a |
List all containers, including stopped ones |
docker exec -it <container_name> /bin/bash |
Access a running container's shell |
docker logs -f <container_name> |
View real-time logs |
docker stop <container_name> |
Stop a container |
docker rm <container_name> |
Delete a stopped container |
docker restart <container_name> |
Restart a container |
3. Volumes and Networks
| Command | Description |
|---|---|
docker volume ls |
List volumes |
docker volume prune |
Remove unused volumes |
docker network ls |
List networks |
docker network inspect <network_name> |
Inspect network details |
4. Docker Compose
| Command | Description |
|---|---|
docker-compose up -d |
Run services in the background |
docker-compose down |
Stop and remove all services |
docker-compose ps |
List running services |
docker-compose logs -f |
View real-time logs |
docker-compose restart <service_name> |
Restart a service |
5. Docker Swarm
| Command | Description |
|---|---|
docker swarm init |
Initialize Swarm mode |
docker stack deploy -c docker-compose.yml <stack_name> |
Deploy a stack |
docker stack rm <stack_name> |
Stop and remove a stack |
docker service ls |
List services |
docker service ps <service_name> |
View service status |
docker service update --force <service_name> |
Restart a service (applies new settings) |
6. Other Useful Commands
| Command | Description |
|---|---|
docker system df |
Check disk usage |
docker system prune |
Remove unused images/containers/volumes |
docker stats |
Monitor real-time container resource usage |
docker inspect <container_name or image_name> |
Inspect detailed information of an object (container or image) |
docker info |
Display current Docker environment information |
journalctl -u docker.service |
Check logs for systemd-based Docker service |
sudo systemctl status docker |
Check the status of the Docker daemon |
sudo systemctl restart docker |
Restart the Docker daemon |
sudo less /var/log/syslog |
Search for Docker-related messages in system-wide logs (Ubuntu) |
I hope this cheatsheet proves helpful to many developers.
Our blog offers a wealth of additional Docker information. Feel free to use the search bar on the right to find topics you're curious about.