Foldable.dev

Web Development

Useful docker commands

Docker is a great tool for development, letting you run your code in little isolated containers on your computer. I find that I often reference the same few docs over and over, so I wanted to make a small cheat sheet that compiles a list of commands I use frequently.

List All Docker Images

To list all of the docker images you've got on your machine, run:

docker images ls --all

List All Docker Containers

To list all of the docker containers you've got on your machine, run:

docker container ls --all

Stop All Docker Containers

To stop all of the running docker containers you've got on your machine, run:

docker container stop --force $(docker container ls --all --quiet)

Remove All Docker Containers

docker container rm $(docker container ls --all --quiet)

You can allso add --force if some containers are currently in use:

docker container rm --force $(docker container ls --all --quiet)

Remove All Docker Images

To remove all of the images (and reclaim some hard disk space):

docker rmi $(docker images --all --quiet)

A Complete Cleanup

Putting it all together, we can stop all of the containers, remove all of the containers, and remove all of the images.

# Stop all containers
docker container stop $(docker container ls --all --quiet)

# Remove all containers
docker container rm $(docker container ls --all --quiet)

# Remove all images
docker rmi $(docker images --all --quiet)