Skip to content

Instantly share code, notes, and snippets.

@kmanwar89
Last active December 19, 2021 21:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmanwar89/884692d5428b76255b9d42c6e9a2c60f to your computer and use it in GitHub Desktop.
Save kmanwar89/884692d5428b76255b9d42c6e9a2c60f to your computer and use it in GitHub Desktop.
Docker Cheatsheet

About: I created a cheatsheet for my own reference as I'm learning about Docker. I found myself often looking up the same commands multiple times and thought to write it all down. Hopefully this helps others!

Information gathering

docker ps -a or docker container list - List all containers

docker ps -aq - List all container ID's

  • This command is useful because it can be called as a variable $(docker ps -aq) and fed into other commands (such as docker stop or docker rm

docker image list - List all docker images

docker system df - Docker disk usage

docker system info - System info

Interacting with containers

docker start - starts any stopped container

docker run - creates & starts the newly-created container

Building

docker build . - build an image from a Dockerfile in the current directory

docker build [-t username/repository:tag] . - build an image from a Dockerfile in the current directory, and optionally tag it.

docker build -t [username/repository:tag] - < [name of dockerfile] - build an image using a Dockerfile read from STDIN

docker build -f [Dockerfile] . - builds from a Dockerfile in an alternate location

docker pull <image name>:[tag] - Retrieve image from repository

docker compose up - create and start containers from a docker-compose.yml file

Cleaning up

docker stop $(docker ps -aq) - stop all running containers by feeding in container ID's

docker stop <container name | container ID> - stop a single container

docker rm $(docker ps -aq) - remove all containers based on container ID. Will not remove containers that haven't been stopped

docker system prune [--volumes] - removes all stopped containers, networks, dangling images/cache and optionally any unused volumes

docker volume prune - removes any unused volumes

docker rmi $(docker images -q) - removes all unused images

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