Many <none> images created after build a docker image - docker

FROM scratch
MAINTAINER Aario <AarioAi#gmail.com>
ENV SHARED_GROUP docker
I build a docker image with above dockerfile.
After runing docker build -t "aario/centos" .
It creates this image aario/centos and the <none> image:
Is it ok? And how to solve it?
When I run docker rmi 2f??????? to remove the aario/centeros image. The <none> image will be removed on the same time.

Docker image is composed of layers:
docker history aario/centos
Each row you see using command above is a separate layer. Also, with time, a number of "orphaned" layers will fill up your disk space. You can safely remove them with:
docker image prune

Those are intermediate image layers. I.e, all of the steps of your Dockerfile.
You can check what these images are made of with inspect command:
docker image inspect 2f???????
They do not use additional disk space, since they are part of your named image. They can save space when you have multiple Dockerfiles with the same steps (in the same order) because they work as cache.
A longer and more complete explanation can be found here.
Eventually, if you delete your image or change build steps, you could have dangling none images. Those can be deleted, as #Mike mentioned, with:
docker image prune

Related

Do intermediate Docker images occupy disk space?

If there are RUN commands in docker file then it does create some intermediate images. My question is whether such intermediate images occupy any memory of your hard drive? If yes, docker build --rm should be enough?
Yes intermediate layers occupy disk space and it is a good thing usually. This facilitates re-use of layers and speedy builds. What you should be concentrating on instead is to reduce the number of layers by optimising the dockerfile. Your final docker image is actually a combination of all the layers. So you cannot remove the layers unless you remove the final image and no other image is using the layers.
docker build --rm does not save any extra disk space. To understand why, you should know how docker build works - Each instruction (e.g., RUN) in a dockerfile starts a new container, after the instruction completes, the container exits, and is committed to an image.
docker build --rm removes these intermediate containers. --rm option is true by default and so docker build --rm has not extra affect compared to docker build. For some reason if you want to keep the intermediate containers then you can turn it off with --rm=False.
If there are any layers which are not being used by any other images, you can remove them. These are called dangling layers. You can remove them with following command -
docker rmi $(docker images -f "dangling=true" -q)
RUN does not create intermediate images, but intermediate layers/containers.
If you run docker build --rm these containers will be deleted after they're generated, so yes it will save space in your disk but will need more time each time you rebuild the same image, since it will create those layers everytime as they are not cached.
Edit (thanks #Shashank V): The --rm option is set by default, so having it or not makes no difference.

Eliminate docker <none> images when building using docker-compose

I am working on a microservice with several docker containers. Using docker-compose creates the images I want but also several other copies of images which fill up my disk space. What are the use of this other child images and can I stop them from being created since they are using up my memory. Please note they are not really "dangling" they just appear on build.
The images are the intermediate layers resulted from docker build. They are the parent layers for your final image and cannot be removed as your latest image actually refers to them.
Only those images which are not referenced by any other layers can be removed. These images are called dangling. You can use the following command to remove the dangling images:
docker rmi $(docker images -f "dangling=true" -q)

What are Dangling Images in Docker/How they created/How to remove them

How do dangling images get created? Whenever I tried to create them it is not happening.
I had used the same concept as mentioned in docker docs. If my DockerFile contains FROM alphine:3.4 then I build the image as docker build -t image1 .
After some time I update it as FROM alphine:3.5 and again building it as docker build -t image1 .
But it is showing me three images no dangling one??
What are Dangling Images in Docker?
Dangling Images are temporary images that are created at the time of building the images in docker server. Since images are build on layers of commits.
How they created?
There are created automatically. You can see them using docker images -f dangling=true
How to remove them?
You can do system purge to remove danggling images like this docker images purge.
If you really want to create a dangling image, simply interrupt the build process before it's finished.
Honestly don't understand why you want to though; they are a by-product of a failed build, that's all.

docker pull always show "Already exists" for layers during pull even after deleting all images

here is my input and output:
shshenhx#shshenhx:~/Desktop/Docker$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python latest 336d482502ab 4 days ago 692 MB
shshenhx#shshenhx:~/Desktop/Docker$ docker rmi 336
Untagged: python:latest
Untagged: python#sha256:bf0718e2882cabc144c9c07d758b09c65efc104a6ddc72a9a976f8b26f67c2ee
Deleted: sha256:336d482502ab564b0b2964b2ed037529ba40c7b4ade2117ca11d74edbf11f99e
Deleted: sha256:1e2f72b0bf844de7bfe57a32115b660770355843ef8078fb55629e720147e6a9
Deleted: sha256:b5818ba96f33835318f3e9d7b4094e1007be247f04ab931ea9ef83b45b451f90
Deleted: sha256:0c2d7cafdab1084ebbd0112b3bedf76458ae6809686fb0ad9bae8022f11c3a84
shshenhx#shshenhx:~/Desktop/Docker$ docker pull python
Using default tag: latest
latest: Pulling from library/python
4176fe04cefe: Already exists
851356ecf618: Already exists
6115379c7b49: Already exists
aaf7d781d601: Already exists
40cf661a3cc4: Already exists
975fe2fd635f: Pull complete
bf4db784e7fd: Pull complete
0491f7e9426b: Pull complete
Digest: sha256:bf0718e2882cabc144c9c07d758b09c65efc104a6ddc72a9a976f8b26f67c2ee
Status: Downloaded newer image for python:latest
My question is, I have already rm python image, why it still shows already exist for some of layers? How can I totally delete all the python layers.
Thanks.
What helped for me was to run docker-system prune after removing all containers and images. So the whole process I got it to work was:
Remove all containers docker rm -vf $(docker ps -a -q)
Remove all images docker rmi -f $(docker images -a -q)
Prune system with docker system prune
From reference of docker images command
Docker images have intermediate layers that increase reusability, decrease
disk usage, and speed up docker build by allowing each step to be cached.
These intermediate layers are not shown by default.
Maybe those Already exists are intermediate layers. By default, they are hided when you run docker images, please try docker images --all.
Docker has a solution for this on docker dashboard, just press the button below and presto it works! (This is in the troubleshooting section. or the bug icon)
There is a docker command that deletes images that do not have an associated running container:
docker image prune
allows you to clean up dangling images (a dangling image is not tagged and not referenced by any container)
docker image prune -a
will remove all images that are not used by any existing containers
docker image prune -a --filter "until=48h"
you can add a filter (--filter) to limit the images to be pruned, as in this example, only images that are older than 48 hours
You can add the -f or --force flag to prune the images and not prompt for confirmation
You could use this in a scheduled bash script to keep your drive tidy
docker system prune -a helped me.It will remove both unused and dangling images.
You can use docker system prune but it will clear everything in docker.
Its not an image problem its actually cache problem so deleting your images wont work because the problem relies in layer caching.
There is a --no-cache flag in docker build but I don't know if it works with docker pull too.
For someone interested in: (1) using the command line; (2) removing cache only for images that have been removed with docker rmi (i.e., not visible with docker images --all), but for which caches are still present, and for which the Already exists shows for layers when pulling image; you can try this command:
docker builder prune
(It may take up to 15 minutes to run this command, so be patient.)
This command seems to have solved the problem for me. I did not want to use the general, "system-wide" prune / purge / clean docker commands and functionalities, because I had some images and containers running (not related to the image that I have already removed), that I wished to have left as they were.
Source of the solution: https://forums.docker.com/t/how-to-delete-cache/5753/7
I think that the situation of "invisible" cached layers for images removed with docker rmi may happen due to the fact of using docker compose (as suggested also by John Doe in his comment to one of the answers in the current question: docker pull always show "Already exists" for layers during pull even after deleting all images).
So after a lot of searching, I have a solution although I don't think it's necessarily a great one.
The "sledge hammer solution" would be to do:
rm -rf /var/lib/docker
This basically factory resets docker, so you would lose everything. This was fine for my case, but be very careful and think this through before using this one.
Please try this command docker rmi 336d482502ab and then try to pull it again.

docker build creates another set of docker image even the build command is the same?

Assume that you can create a 500MB docker image with following command
docker build -t demo:1.0 .
It seems to me that the docker image (demo:1.0) is overwritten when I re-run the same command. However, I noticed that free disk space decreases as I re-run the command. Why does this happen? Is docker creating another set of the image somewhere in the file system? I'd like to know how I can find old-generations of the docker images and delete them.
It's standard docker behavior, if you run
docker images
you may see a dangling image like this
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
demo 1.0 a1b38444260e 6 days ago 500 MB
<none> <none> 46250b7172c5 6 days ago 500 MB
You can remove the dangling images with the command
docker rmi $(docker images -qa -f "dangling=true")
Docker doesn’t delete such images automatically, despite, it's a logical feature to have. For now this command can be used to do a manual deletion.
While the images are stored in /var/lib/docker/{driver-name}, you wouldn't remove images manually from that path.

Resources