# Docker Cheat Sheet: Standard & Docker Compose Commands

> A concise Docker cheat sheet of essential CLI commands for containers, images, logs, and Docker Compose, plus system cleanup commands like docker system prune.

- URL: https://codethepixel.com/docker-cheat-sheet-standard-docker-compose-commands
- Author: Asyraf Wahi Anuar (https://codethepixel.com/author/asyraf-wahi-anuar)
- Published: 2026-11-11
- Category: Docker
- Level: Intermediate
- Tested with: Docker
- Tags: Docker
- Reading time: 2 min

## Key takeaways

- This cheat sheet covers essential Docker CLI commands for containers, images, logs, debugging, and system cleanup.
- Use docker run -d -p 8080:80 --name my-container nginx to start a container in the background with port mapping.
- docker logs -f streams container logs in real-time, and docker exec -it  bash opens an interactive shell.
- Docker Compose commands include docker compose up -d, down, ps, logs -f, restart, and build.
- docker system prune removes stopped containers, unused networks, and dangling images to free disk space.

Working with Docker and Docker Compose involves managing various containers, images, volumes, and networks daily. Remembering every single syntax and flag can be challenging—especially when setting up quick development environments or troubleshooting server deployments.

This reference guide provides a concise Docker Cheat Sheet covering the most essential CLI commands and their practical descriptions. Keep this page bookmarked for a quick reference whenever you need to spin up containers, check service logs, or manage multi-container applications.

## 1. Docker Lifecycle & Management Commands

| **Command** | **Description** |
| --- | --- |
| `docker run -d -p 8080:80 --name my-container nginx` | Download and start a container in the background (`-d`), mapping port 8080 on the host to port 80 inside the container. |
| `docker ps` | List all currently running containers. |
| `docker ps -a` | List all containers (both running and stopped). |
| `docker stop <container_name_or_id>` | Gracefully stop a running container. |
| `docker start <container_name_or_id>` | Start a stopped container. |
| `docker restart <container_name_or_id>` | Restart a running or stopped container. |
| `docker rm <container_name_or_id>` | Remove a stopped container (add `-f` to force-remove a running one). |

## 2. Docker Logs & Debugging

| **Command** | **Description** |
| --- | --- |
| `docker logs <container_name_or_id>` | View the standard output logs of a container. |
| `docker logs -f <container_name_or_id>` | Stream container logs in real-time (like `tail -f`). |
| `docker exec -it <container_name_or_id> bash` | Open an interactive bash terminal inside a running container (use `sh` if bash is unavailable). |

## 3. Docker Image Commands

| **Command** | **Description** |
| --- | --- |
| `docker images` | List all locally stored Docker images. |
| `docker pull <image_name>:<tag>` | Download a Docker image from Docker Hub without running it. |
| `docker build -t <image_name> .` | Build a Docker image from a `Dockerfile` in the current directory. |
| `docker rmi <image_name_or_id>` | Delete a local Docker image. |

## 4. Docker Compose Commands

| **Command** | **Description** |
| --- | --- |
| `docker compose up -d` | Build, (re)create, and start containers in the background using the `docker-compose.yml` file. |
| `docker compose down` | Stop and remove all containers, networks, and default volumes defined in the compose file. |
| `docker compose ps` | List containers managed by the current `docker-compose.yml` file. |
| `docker compose logs -f` | Follow log output from all services defined in the compose file. |
| `docker compose restart` | Restart all services defined in the compose file. |
| `docker compose build` | Rebuild service images from scratch without starting them. |

## 5. System Cleanup Commands

| **Command** | **Description** |
| --- | --- |
| `docker system prune` | Remove all stopped containers, unused networks, and dangling images to free up disk space. |
| `docker system prune -a --volumes` | Remove *all* unused containers, networks, images (not just dangling ones), and volumes. *(Gunakan dengan cermat)* |
