Cheat sheet
The following are some of the ways to remove docker images/containers:
Remove single image
docker rmi image_name:version/image-id
Remove all images
docker rmi $(docker images -qf "dangling=true")
Kill containers and remove them:
docker rm $(docker kill $(docker ps -aq))
Note: Replace
kill
with stop
for graceful shutdownRemove all images except "my-image"
Use grep to remove all except
my-image
and ubuntu
docker rmi $(docker images | grep -v 'ubuntu\|my-image' | awk {'print $3'})
Or (without awk)
docker rmi $(docker images --quiet | grep -v $(docker images --quiet ubuntu:my-image))
Delete all docker containers
docker rm $(docker ps -a -q)
Delete all docker images
docker rmi $(docker images -q)
Removing Containers
-
To remove specific container
docker rm CONTAINER_ID CONTAINER_ID
-
For single image
docker rm 70c0e19168cf
-
For multiple images
docker rm 70c0e19168cf c2ce80b62174
-
Remove exited containers
docker ps -a -f status=exited
-
Remove all the containers
docker ps -q -a | xargs docker rm
Removing Images
docker rmi IMAGE_ID
-
Remove specific images
-
for single image
docker rmi ubuntu
-
for multiple images
docker rmi ubuntu alpine
-
Remove dangling images
Dangling images are layers that have no relationship to any tagged images as the Docker images are constituted of multiple images.
docker rmi -f $(docker images -f dangling=true -q)
-
Remove all Docker images
docker rmi -f $(docker images -a -q)
Removing Volumes
To list volumes run docker volume ls
-
Remove a specific volume
docker volume rm VOLUME_NAME
-
Remove dangling volumes
docker volume rm $(docker volume ls -f dangling=true -q)
-
Remove a container and its volumes
docker rm -v CONTAINER_NAME
Kommentarer
Send en kommentar