[[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 : .` | Build an image from a Dockerfile in the current directory |
| `docker images` | List local images |
| `docker rmi ` | Delete an image |
| `docker pull ` | Pull an image from a remote repository |
| `docker push ` | Push an image to a repository (requires login) |
## 2. Container-Related Commands
| Command | Description |
| --- | --- |
| `docker run -d --name -p 8000:8000 ` | Run a container in the background |
| `docker ps` | List currently running containers |
| `docker ps -a` | List all containers, including stopped ones |
| `docker exec -it /bin/bash` | Access a running container's shell |
| `docker logs -f ` | View real-time logs |
| `docker stop ` | Stop a container |
| `docker rm ` | Delete a stopped container |
| `docker restart ` | 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 ` | 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 ` | Restart a service |
## 5. Docker Swarm
| Command | Description |
| --- | --- |
| `docker swarm init` | Initialize Swarm mode |
| `docker stack deploy -c docker-compose.yml ` | Deploy a stack |
| `docker stack rm ` | Stop and remove a stack |
| `docker service ls` | List services |
| `docker service ps ` | View service status |
| `docker service update --force ` | 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 ` | 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.