🐳 Docker

Command Reference & Compose Guide

Containers
docker run -d -p 8080:80 image
Run container detached, map host:container port
docker run -it --rm image bash
Interactive shell, auto-remove on exit
docker run --name myapp -e KEY=val image
Named container with environment variable
docker run -v ./data:/data image
Bind-mount host directory into container
docker ps
List running containers
docker ps -a
List all containers including stopped
docker stop id|name
Gracefully stop a container (SIGTERM → SIGKILL)
docker rm id|name
Remove a stopped container
docker exec -it name bash
Shell into a running container
docker logs -f name
Stream live container logs
docker inspect name
Full JSON metadata for a container or image
docker stats
Live CPU/mem/net usage for all containers
Images
docker pull image:tag
Download image from registry
docker build -t name:tag .
Build image from Dockerfile in current dir
docker build --no-cache -t name:tag .
Force full rebuild, ignore layer cache
docker images
List local images
docker rmi image:tag
Remove a local image
docker tag src:tag dst:tag
Alias an image with a new name/tag
docker push name:tag
Push image to registry
docker history image
Show layers and sizes of an image
Volumes & Networks
docker volume create vol
Create a named volume
docker volume ls
List all volumes
docker volume rm vol
Delete a volume
docker network create net
Create a bridge network
docker network ls
List networks
docker network inspect net
Show containers attached and subnet info
Cleanup
docker system prune
Remove stopped containers, dangling images, unused networks
docker system prune -a
Also remove all unused images (not just dangling)
docker image prune -a
Remove all images not used by a running container
docker volume prune
Remove all unused volumes