Skip to content

Instantly share code, notes, and snippets.

@mapcloud
Last active December 18, 2017 13:48
Show Gist options
  • Save mapcloud/1b0a76b57c7ac8ed1cabbd21427238d2 to your computer and use it in GitHub Desktop.
Save mapcloud/1b0a76b57c7ac8ed1cabbd21427238d2 to your computer and use it in GitHub Desktop.
How to Delete All <none>, Untagged and dangling Docker Containers and Images?

Transfer docker image to non-internet-connected machine

Create a backup that can then be used with docker load

$ docker save busybox > busybox.tar

$ ls -sh busybox.tar

2.7M busybox.tar

or

$ docker save --output busybox.tar busybox

Save to disk:

$ docker save -o ubuntu_image.docker ubuntu

Transfer the file to the offline computer and load the image from the file (use USB flash drive):

$ docker load -i ubuntu_image.docker

General uses:

Root.

$ docker exec -u 0 -it {container_id/image_name} bash

or

Default container's user.

$ docker exec -it {container_id/image_name} bash

How to Delete All , Untagged and dangling Docker Containers and Images?

While you build docker images, it is likely that many untagged images get piled up. This topic covers how to delete those images and keep your docker host neat and clean.

For docker version >= 1.13

If you are using docker version 1.13 and above, the following commands will do the trick.

Complete System Cleanup

While you build docker images, it is likely that many untagged images get piled up. This topic covers how to delete those images and keep your docker host neat and clean.

For docker version >= 1.13

If you are using docker version 1.13 and above, the following commands will do the trick.

Complete System Cleanup

To cleanup, all unused containers, images, network, and volumes, use the following command.

To clean up, all unused containers, images, network, and volumes, use the following command.

docker system prune

docker system prune

Recommended: Learn Docker Technologies for DevOps and Developers

To individually delete all the components, use the following commands.

docker container prune
docker image prune
docker network prune
docker volume prune

For Docker versions below 1.13

To clean up containers, first, you need to clean up your containers. So that all the unwanted images can be deleted without dependency problems.

Delete all Exited Containers

docker rm $(docker ps -q -f status=exited)

Delete all Stopped Containers

docker rm $(docker ps -a -q)

Delete All Running and Stopped Containers

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Delete all "none" Images

docker rmi $(docker images | grep "^<none>" | awk '{ print $3 }')

Delete all Dangling Images

docker rmi $(docker images -f "dangling=true" -q)	

To individually delete all the components, use the following commands.

docker container prune
docker image prune
docker network prune
docker volume prune

For Docker versions below 1.13

To clean up containers, first, you need to clean up your containers. So that all the unwanted images can be deleted without dependency problems.

Delete all Exited Containers

docker rm $(docker ps -q -f status=exited)

Delete all Stopped Containers

docker rm $(docker ps -a -q)

Delete All Running and Stopped Containers

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Delete all "none" Images

docker rmi $(docker images | grep "^<none>" | awk '{ print $3 }')

Delete all Dangling Images

sudo docker rmi $(sudo docker images -f "dangling=true" -q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment