Docker
Containers, images, logs, Docker Compose and disk cleanup.
Containers
Running containers
docker psAll containers, including stopped
docker ps -aRun a container in the background with a published port
docker run -d --name <container> -p 8080:80 <image>
Open a shell inside a container
docker exec -it <container> sh
Stop and remove a container
docker rm -f <container>
Remove exited containers
docker rm $(docker ps -a -q -f status=exited)Remove created containers
docker rm $(docker ps -a -q -f status=created)Follow logs
docker logs -f --tail 100 <container>
CPU and memory usage
docker statsContainer IP addressadvanced
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container>
\{{end}} is an escaped Go template — it is copied as {{end}}.
Images
List images
docker imagesBuild an image
docker build -t <image> .
Build for another platformadvanced
docker buildx build --platform linux/amd64 -t <image> --push .
Copy a file out of a container
docker cp <container>:/path/in/container ./local-path
Docker Compose
Start everything in the background
docker compose up -dRebuild and start
docker compose up -d --buildStop and remove containers
docker compose downStop and remove including volumes
docker compose down -vService logs
docker compose logs -f <compose_service>
Run a command in a service
docker compose exec <compose_service> sh
Cleanup
How much space Docker uses
docker system dfRemove everything unusedadvanced
docker system prune -a --volumesRemoves all stopped containers, unused images, networks and volumes. Data in volumes will be lost!