====== Docker CheatSheet ====== Basic docker commands ===== Update a docker compose ===== ''docker compose pull'' ''docker compose up -d'' ===== Container Management ===== A container is a running instance of an image. ^ Command ^ Description ^ | ''docker ps'' | List running containers | | ''docker ps -a'' | List **all** containers (including stopped ones) | | ''docker start '' | Start a stopped container | | ''docker stop '' | Gracefully stop a running container | | ''docker restart ''| Restart a container | | ''docker rm '' | Remove a container (must be stopped first) | | ''docker rm -f '' | Force removal of a running container | ===== Image Management ===== An image is the blueprint downloaded from Docker Hub. ^ Command ^ Description ^ | ''docker images'' | List all locally stored images | | ''docker pull '' | Download an image from Docker Hub (e.g., ''docker pull nginx'') | | ''docker rmi '' | Remove a local image | ===== Troubleshooting & Logs ===== Essential when a homelab service isn't working as expected. ^ Command ^ Description ^ | ''docker logs '' | Display container logs | | ''docker logs -f '' | Follow logs in real-time (tail -f) | | ''docker exec -it /bin/bash''| Open an interactive terminal (bash) inside the container | | ''docker exec -it /bin/sh'' | Open a terminal (sh) if bash is unavailable (common on Alpine) | | ''docker stats'' | Display live CPU/RAM usage of all containers | | ''docker inspect '' | Display detailed container info (IP, network, volumes) in JSON format | | ''docker build -t .'' | Build an image from the Dockerfile in the current directory | ===== Cleanup (Prune) ===== To free up disk space on the server. **Use these commands with caution!** ^ Command ^ Description ^ | ''docker container prune'' | Remove all stopped containers | | ''docker image prune'' | Remove dangling images (no tags, not associated with a container) | | ''docker volume prune'' | Remove unused volumes (risk of data loss) | | ''docker system prune -a'' | Deep clean: remove everything that is not currently in use | ===== Docker Compose ===== To manage multi-container stacks (via a ''docker-compose.yml'' file). ^ Command ^ Description ^ | ''docker compose up -d'' | Create and start containers in the background (detached mode) | | ''docker compose down'' | Stop and remove containers and networks defined in the stack | | ''docker compose pull'' | Pull the latest images defined in the compose file | | ''docker compose logs -f'' | Follow logs for the entire stack in real-time |