Docker Cheat Sheet
Here are a collection of docker commands I use in bash every day. If you're using Powershell or Windows command line you may need to adjust them slightly.
Containers
Show currently running containers:
docker ps
Show all containers (including stopped ones):
docker ps -a
Remove container:
docker rm <container-id>
Remove all containers:
docker rm -f $(docker ps -a -q)
View the logs of a container:
docker logs <container-id>
Inspect a container:
docker inspect <container-id>
Images
Remove image:
docker rmi <image-id>
Remove all images:
docker rmi $(docker images -q)
Networks
Show networks:
docker network ls
Remove network:
docker network rm <network-id>
Tips
Short IDs
Don't forget that when referencing the ID of a container, image or network you only need to use the first few characters for it to work. As long as they are unique to that Docker instance then the ID will be understood.
For instance if I wanted to view the logs of a container with the ID 4c01db0b339c
I can get away with just typing docker logs 4
. As long as there are no other containers with an ID starting with 4
then Docker will perform the requested action.