When I run docker image ls I see this
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> c012c1e2eb45 4 hours ago 2.59GB
<none> <none> a2013debf751 5 hours ago 2.59GB
<none> <none> 0bbb2f67083c 5 hours ago 2.59GB
<none> <none> af18b070061b 29 hours ago 182MB
<none> <none> 186a8fac122e 35 hours ago 1.67GB
<none> <none> 0f90c1bb12a3 35 hours ago 182MB
<none> <none> b94009e70416 13 days ago 631MB
<none> <none> 880d8e6713cf 2 weeks ago 631MB
b/2018-external latest 128d208a6c83 2 weeks ago 207MB
2018-external latest 128d208a6c83 2 weeks ago 207MB
b/2018-web <none> 128d208a6c83 2 weeks ago 207MB
nginx latest 9e7424e5dbae 2 weeks ago 108MB
node 8-alpine 4db2697ce114 4 weeks ago 67.7MB
b_web latest d5a0ea011c0a 5 weeks ago 182MB
<none> <none> 957c22ababec 5 weeks ago 182MB
docker_web latest 70b443ed0495 5 weeks ago 182MB
docker_app latest 509d58a68224 5 weeks ago 756MB
b_app latest 509d58a68224 5 weeks ago 756MB
mysql 5.6 96dc914914f5 5 weeks ago 299MB
mysql latest 5fac85ee2c68 8 weeks ago 408MB
redis latest 1fb7b6c8c0d0 2 months ago 107MB
alpine 3.6 76da55c8019d 2 months ago 3.97MB
nginx 1.13.3-alpine ba60b24dbad5 5 months ago 15.5MB
keymetrics/pm2-docker-alpine 6 4a09bfc067d6 5 months ago 75.3MB
dockercloud/cli latest 051238cd0a37 6 months ago 64.2MB
andrewmclagan/nginx-hhvm latest ec6cc741eb0e 7 months ago 580MB
nginx 1.10 0346349a1a64 8 months ago 182MB
php 7.0.8-fpm 75b880f3a420 17 months ago 375MB
tutum/haproxy latest 33bc771bec1e 18 months ago 232MB
php 7.0.4-fpm 81d7a2fdc6dc 21 months ago 494MB
How do I know if which image are safely to remove ?
My attention is to remove all of them, but I am not sure if I should be more carful before doing that.
You can use docker image prune to remove "dangling" images; those that are not tagged (eg <none>) and are not referenced by any running container.
I find the docker image prune -a more useful. It will remove any image that is not used by a running container. In that sense prune -a is a cleanup step that you can take after your environment is running correctly.
Images that are referred to as dangling are safe to remove. Those are the images that don't have a tag. They result when a new build of an image appears and the new image takes the tag leaving the dangling images with <none>:<none>
tag.
Dangling images can be listed using docker images --filter "dangling=true" and can be removed by running docker image prune.
This command also work for me.
docker rmi $(docker images -f "dangling=true" -q)
Purging All Unused or Dangling Images, Containers, Volumes, and Networks:
Clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):
docker system prune
Remove any stopped containers and all unused images (not just dangling images):
docker system prune -a
Remove one or more specific images:docker rmi Image Image
Remove dangling images:docker images purge
Removing images according to a pattern:docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi
Remove all images:docker rmi $(docker images -a -q)
Remove one or more specific containers: docker rm ID_or_Name ID_or_Name
Remove a container upon exit(run and remove): docker run --rm image_name
Remove all exited containers: docker rm $(docker ps -a -f status=exited -q)
Remove containers using more than one filter: docker rm $(docker ps -a -f status=exited -f status=created -q)
Stop and remove all containers:
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
Origin article: digitalocean
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I have made a Dockerfile to build an image which is based on another Dockerfile. It uses Alpine Linux as a base.
Everything works fine, but when I view the images with the --all switch, I get multiple instances of what appears to be my image and the image for Alpine Linux which it is based on:
$ docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 5577c25bccd9 20 hours ago 137MB
<none> <none> 48f944e609b5 20 hours ago 137MB
paradroid/myapp latest f2a0f99986a6 20 hours ago 137MB
<none> <none> d846706db3f4 20 hours ago 137MB
<none> <none> f1410e1d307e 20 hours ago 137MB
<none> <none> e52e6203864a 20 hours ago 137MB
<none> <none> dd3be52289ce 20 hours ago 5.59MB
<none> <none> 8559960a8bd0 20 hours ago 5.59MB
<none> <none> 04020d8307b3 20 hours ago 5.59MB
<none> <none> fe0f1e73261c 20 hours ago 5.59MB
<none> <none> 12229a67b395 20 hours ago 5.59MB
alpine latest cc0abc535e36 13 days ago 5.59MB
This does not happen when building the Dockerfile which it is based on.
docker system prune does not remove them and any attempt to delete them individually gives this response:
$ docker image rm d846706db3f4
Error response from daemon: conflict: unable to delete d846706db3f4 (cannot be forced) - image has dependent child images
How can I find out what is causing this?
The <none:none> images are the intermediate layers resulted from your docker build.
Docker image is composed of layers. Each instruction in your Dockerfile results in a layer. These layers are re-used between different images. This results in efficient usage of disk space. So if a is layer being used by another image, you won't be able to delete the layer.
You can run the following command which will remove the layers which are not referenced in any of the images. These layers are called dangling.
docker rmi $(docker images -f "dangling=true" -q)
https://www.projectatomic.io/blog/2015/07/what-are-docker-none-none-images/
use
docker image rm -f imageid
for multiple
docker image rm -f imageid imageid
I have 3 containers, but I have a lot of images as you can see in the image.
⚡️ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sscportalsmb_smb-portal latest ad0854c799f6 12 days ago 17.6MB
bheng_web latest d5a0ea011c0a 2 weeks ago 182MB
<none> <none> 957c22ababec 2 weeks ago 182MB
docker_web latest 70b443ed0495 2 weeks ago 182MB
bheng_app latest 509d58a68224 2 weeks ago 756MB
docker_app latest 509d58a68224 2 weeks ago 756MB
mysql 5.6 96dc914914f5 2 weeks ago 299MB
sscportalapi_ssc-portal-api latest e8295f9cb5f1 4 weeks ago 160MB
sscportaladmin_admin-portal latest fd141ceba4d6 4 weeks ago 17.7MB
mysql latest 5fac85ee2c68 5 weeks ago 408MB
redis latest 1fb7b6c8c0d0 6 weeks ago 107MB
alpine 3.6 76da55c8019d 2 months ago 3.97MB
keymetrics/pm2-docker-alpine 6 4a09bfc067d6 4 months ago 75.3MB
andrewmclagan/nginx-hhvm latest ec6cc741eb0e 7 months ago 580MB
nginx 1.10 0346349a1a64 7 months ago 182MB
tutum/haproxy latest 33bc771bec1e 17 months ago 232MB
php 7.0.4-fpm 81d7a2fdc6dc 20 months ago 494MB
I am not sure if this is normal.
How do I check for images that I don't use and get rid of them accordingly?
Above answers help us find and remove the dangling images,, but not unused.
So to fetch all the unused docker images on the machine
Fetch all the images belonging to the running containers(which are not stopped or exited)
Fetch all the images on the machine
Then filter the images in step 1 from step 2
Below is the basic shell script which could help do that
runningImages=$(docker ps --format {{.Image}})
docker images --format {{.Repository}}:{{.Tag}} | grep -v "$runningImages"
Just be sure before removing unused images(not the dangling ones) just list them and then decide which one to delete manually.
You can find unused images using the command:
docker images -f dangling=true
and just a list of their IDs:
docker images -q -f dangling=true
In case you want to delete them:
docker rmi $(docker images -q -f dangling=true)
Docker added special commands for this not so long ago:
docker image prune -> https://docs.docker.com/engine/reference/commandline/image_prune/ for removing unused images and docker container prune -> https://docs.docker.com/engine/reference/commandline/container_prune/ for stopped containers.
Comparing the result of docker images and of docker ps you should be able to understand what images are used in a running container. The second column of the output of docker ps is indeed the image used.
I noticed that Docker appears to be using a large amount of disk space. I can see the directory /Users/me/.docker/machine/machines/default is 27.4GB
I recently cleaned up all of the images and containers I wasn't using. Now, when I run docker ps I see that no images are running.
~ $ docker ps
I can also see that I have 2 containers available.
~ $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
42332s42d3 cds-abm "/bin/bash" 2 weeks ago Exited (130) 2 weeks ago evil_shockley
9ssd64ee41 tes-abm "/bin/bash" 2 weeks ago Exited (130) 2 weeks ago lonely_brattain
I can then see I have 3 images.
~ $ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ghr/get latest 6708fffdd4dfa 2 weeks ago 2.428 GB
<none> <none> 96c5974ddse18 2 weeks ago 2.428 GB
fdbh/ere latest bf1da53766b1 2 weeks ago 2.225 GB
How can these be taking up nearly 30GB?
It is because you are not removing the volumes created by the containers when you stop the container. In the future, use -v when you remove the containers.
docker rm -v <container-id>
Regrading cleaning up the space, you have to ssh into docker-machine and remove all volumes created. To do so,
docker-machine ssh default
sudo -i # You may not get permission to enter in to volumes directory
cd /var/lib/docker/volumes
rm -rf *
Make sure none of your containers are currently running. Also, make sure that you don't need any of these volumes for later use (like DB containers).
I am unable to explicitly delete some untagged docker images. Specifically, those with the tag <none>.
If I run docker images -a I get something like this:
<none> <none> 91e54dfb1179 3 months ago 188.3 MB
<none> <none> d74508fb6632 3 months ago 188.3 MB
<none> <none> c22013c84729 3 months ago 188.3 MB
<none> <none> d3a1f33e8a5a 3 months ago 188.1 MB
<none> <none> 4a5e6db8c069 3 months ago 125.1 MB
<none> <none> 2c49f83e0b13 3 months ago
However, when I type docker rmi -f 2c49f83e0b13 I get:
Error response from daemon: Conflict, 2c49f83e0b13wasn't deleted
Error: failed to remove images: [2c49f83e0b13]
Any idea what could be the problem?
These might be intermediary docker images for some images I'm actually using. But if that's the case, then the completed docker images should already have those prior images and I don't explicitly need those intermediary images to be there.
Make sure the image is actually dangling (meaning it is not referenced by any other image, or is not parent of an image)
docker images --filter "dangling=true" -q --no-trunc
If it is dangling (and should be removed), then there is a couple of pending bug reporting the impossibility to delete such images: issue 13625, issue 12487.
The container should be stopped first before you can remove the image :
docker rm $(docker ps -a -q)
Source : https://github.com/docker/docker/pull/6112
It happen to me also and restarting the docker engine and all the containers using this image solve the issue.
docker ps -aq
Shows only 7-9 images.
/var/lib/docker/graph
shows me n number of images.
When I create a file, I get write error due to system full error. I tried to create symbolic link. but I cannot able to move all the docker things.
Is it good to remove everything under /var/lib/docker/graph? What are the other possibilities than creating symbolic link and extending disk? I would prefer deleting unnecessary things.
<none> <none> 02a16288ef14 6 days ago 773.3 MB
<none> <none> 21a606deee7e 6 days ago 773.3 MB
<none> <none> 8a38f2888018 6 days ago 773.2 MB
<none> <none> f41395b7637d 6 days ago 773.3 MB
<none> <none> 8b82d707167c 6 days ago 773.3 MB
To get rid of "dangling" images, run the following:
$ docker rmi $(docker images -q -f dangling=true)
That should clear out all the images marked "none". Be aware however, that images will share base layers, so the total amount of diskspace used by Docker will be considerably less than what you get by adding up the sizes of all your images.
Use docker ps -a to get the container ID and image ID. You can remove the container with
docker rm <containerID>
Then you can remove the image with
docker rmi <imageID>
According to the answer given here,
/var/lib/docker/aufs/diff/ has the file contents of the images.
/var/lib/docker/graph/ now only contains metadata about the
image, in the json and layersize files.
/var/lib/docker/repositories-aufs is a JSON file containing local
image information. This can be viewed with the command docker images.
Refer to this link, Docker containers can be stopped and deleted by the following commands
docker ps
docker stop
docker rm containerid
docker rmi imageid
I faced the similar issue running out of space. Then I realized that dangling docker volumes are eating up space.
You can delete the dangling docker volumes with the following command
docker volume rm $(docker volume ls -qf dangling=true)