Docker commands - bradsorour/notes GitHub Wiki
Removing docker containers
To stop all containers:
$ docker stop $(docker ps -a -q)
To remove all containers:
$ docker rm $(docker ps -a -q)
To remove all stopped containers:
$ docker container prune
Removing docker images
To remove one or more Docker images use the docker images ls command to find the ID of the images you want to remove.
$ docker image ls
Once you’ve located the images you want to remove, pass their IMAGE ID to the docker image rm command. For example, to remove the first two images listed in the output above run:
$ docker image rm 75835a67d134 2a4cca5ac898
Remove dangling images
Docker provides a docker image prune command that can be used to remove dangled and unused images. A dangling image is an image that is not tagged and is not used by any container. To remove dangling images type:
$ docker image prune
Remove all unused images
To remove all images which are not referenced by any existing container, not just the dangling ones, use the prune command with the -a flag:
$ docker image prune -a
Remove all unused volumes
Remove all unused volumes To remove all unused volumes use the docker image prune command:
$ docker volume prune
Remove all unused networks
Use the docker network prune command to remove all unused networks.
$ docker network prune
Troubleshooting
If unable to bring containers down due to an error similar to this:
ERROR: network docker_default has active endpoints
Then run the command $ docker network inspect docker_default to see what containers are attached to the network.
Run $ docker rm mysql -f to stop the attached mysql container. Then remove the network with $ docker network disconnect -f docker_default mysql