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!
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
ordocker rm
docker image list
- List all docker images
docker system df
- Docker disk usage
docker system info
- System info
docker start
- starts any stopped container
docker run
- creates & starts the newly-created container
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
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