Skip to content

Instantly share code, notes, and snippets.

@jamesmurdza
Last active March 11, 2023 07:45
Show Gist options
  • Save jamesmurdza/d7dced2298caa670d6fbaff871200eca to your computer and use it in GitHub Desktop.
Save jamesmurdza/d7dced2298caa670d6fbaff871200eca to your computer and use it in GitHub Desktop.

🐳 Docker Cheatsheet

Build and run

Build an image:

docker build -t myimage .

Build an image, deleting the old one:

docker rmi myimage && docker build -t myimage .

Build an image, and print all the steps:

docker build --progress=plain -t myimage .

Run container from image, with port forwarding:

docker run -p 80:80 myimage

Run container for debugging purposes, replacing the entrypoint with a shell:

docker run --rm -it --entrypoint bash myimage

Inventory

List all images:

docker image ls

List all containers: (The -a flag is to show stopped containers as well)

docker container ls -a

List all docker images and containers and file sizes:

docker system df -v

Show the history of an image:

docker history myimage

Clean up

Dangling images are untagged and not needed by any tagged images. Unused image are not needed by any existing containers.

Delete stopped containers:

docker container prune

Remove dangling images:

docker image prune

Remove unused images:

docker image prune -a

Remove build cache:

docker builder prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment