Skip to content
Latchkey

Docker CLI Cheat Sheet: Every Command You Use Daily

Every Docker CLI command and the flags you actually use, in one reference.

Containers, images, volumes, and cleanup - the docker CLI essentials.

Containers

CommandDoes
docker run --rm -it img shRun interactively, auto-remove
docker run -d -p 8080:80 imgDetached, publish port
docker ps -aList all containers
docker exec -it id shShell into running container
docker logs -f idFollow logs
docker stop / rm idStop / remove
docker cp id:/path ./localCopy file out

Images

CommandDoes
docker build -t name:tag .Build image
docker imagesList images
docker pull / push namePull / push registry
docker tag src dstRe-tag
docker rmi nameRemove image
docker history nameInspect layers

Volumes & networks

CommandDoes
docker volume ls / createList / create volumes
docker run -v vol:/data imgMount named volume
docker run -v $PWD:/app imgBind-mount cwd
docker network ls / createList / create networks

Cleanup

CommandReclaims
docker system prune -afStopped containers, dangling images
docker system prune -af --volumesAbove + unused volumes
docker image prune -aUnused images
docker builder pruneBuild cache

Key takeaways

  • --rm avoids piling up stopped containers in CI.
  • system prune -af --volumes is the safe CI disk reclaimer.
  • Bind-mount with $PWD for live local dev; named volumes for persistence.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →