Docker cheat sheet
Run it, get a shell in it, read its logs, build it, push it, and reclaim your disk afterwards. Docker and Docker Compose commands for every day.
In Snippet Keeper, click Import at the bottom of the sidebar and choose the file. They land in your docker app, and ones you already have are skipped. The highlighted parts become fill-in fields: type a value (or pick one), and the finished command is on your clipboard.
Containers
docker run --rm -it image shell
docker run -d --name name -p host_port:container_port image
docker run --rm -it -v "$(pwd)":/app -w /app image shell
docker run --rm --env-file env_file image
docker ps
docker ps -a
docker exec -it container shell
docker logs -f --tail lines container
docker rm -f container
docker cp container:path dest
docker stats
docker inspect container
Images
docker build -t name:tag .
docker buildx build --platform platform -t name:tag .
docker build --no-cache -t name:tag .
docker images
docker pull image
docker tag image registry/image && docker push registry/image
docker login registry
docker history image
Cleanup
docker system df
docker container prune -f
docker image prune -f
docker system prune -af --volumes
Volumes and networks
docker volume ls
docker network create network
docker run -d --network network --name name image
Compose
docker compose up -d
docker compose up -d --build
docker compose down -v
docker compose ps
docker compose logs -f service
docker compose exec service shell
docker compose run --rm service command
docker compose restart service
Keep these one keystroke away.
Snippet Keeper is a Mac app for the commands you keep looking up. Press ⌥⇧Space in any app, type a few letters, fill in the blanks, and it’s on your clipboard.