Docker Delete daemon - docker

I want to delete a Docker daemon; because it take more space on my pc
I did insert a code to install php:5.3-apache
I used this command docker build -t my-php-app .
I get this error
Sending build context to Docker daemon 7.039GB
Error response from daemon: unexpected error reading Dockerfile: read /var/lib/docker/tmp/docker-builder079515785/dockerfile: is a directory
so I want to delete that daemon because It take big space on my pc; I did tried 3 times to install it and every-time I get the same error so I have now more than 21GB that I want to clean.
docker images give me :
orsolin/docker-php-5.3-apache latest d8e72369c6e9 2 years ago 533MB
but space on my computer has been decreased from 30GB to 8GB
I don't see anything with 7GB of size
REPOSITORY TAG IMAGE ID CREATED SIZE
abv_web latest 2194cdd678e3 45 hours ago 5.09GB
<none> <none> 58b330f4aa2f 46 hours ago 623MB
<none> <none> c4b5c889111d 46 hours ago 623MB
<none> <none> cfe4161b5af4 46 hours ago 623MB
<none> <none> f37f2a95529a 46 hours ago 623MB
httpd latest 19459a872194 4 days ago 154MB
phpmyadmin/phpmyadmin latest d8d2c1fd1eb9 9 days ago 458MB
phpmyadmin/phpmyadmin edge 4b557b055a8c 9 days ago 458MB
pweb_joomla latest 22c6d70d575e 10 days ago 1.01GB
fweb_joomla latest 0e36548560af 11 days ago 2.47GB
joomla apache 73acf8852f1b 13 days ago 461MB
mysql 5.6 732765f8c7d2 4 weeks ago 257MB
joomla 3.9.5-apache 398227376f4a 4 months ago 415MB
alterway/php 5.3-apache 87058120bc90 8 months ago 623MB
orsolin/docker-php-5.3-apache latest d8e72369c6e9 2 years ago 533MB
airinuit_mysql latest fa73519d1891 2 years ago 304MB
vsamov/mysql-5.1.73 latest fa73519d1891 2 years ago 304MB

Docker internally runs on a client/server architecture. In particular, when you run docker build, it creates a tar file of the directory you specify, sends that tar file across a socket to the Docker daemon, and unpacks it there. (True even on a totally local system.)
If something goes wrong, that content can back up in /var/lib/docker/tmp. Usually you shouldn’t be poking around in /var/lib/docker at all, but cleaning out this directory should be safe. Consider stopping the daemon while you do it. Stopping the daemon, deleting all of /var/lib/docker, and restarting the daemon should also help (you will need to re-docker build and/or docker pull images and re-run containers, and this will lose anything in named volumes you haven’t backed up).
The 7.039 GB build context is very large. In addition to problems like this it will just result in the docker build step being very slow; if all of that content gets COPYEd into the image you will probably hit similar problems trying to docker push the built image. You can try cleaning up things like log files or heap dumps if those are left lying around; adding things like your .git directory or a local vendor tree to a .dockerignore file can also help reduce the size of the context.

You don't want to delete the daemon, the daemon is actually the piece of software running on your host machine that able you to run docker commands.
If you want to remove existing images, volumes, containers, networks, build caches, you can dig into the command
docker system prune
Be careful with it, it will delete a lot things that you possibly still might use.
If you want to identify what does takes space in your host, prior to rennung any clean up, you can also run
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 5 2 16.43 MB 11.63 MB (70%)
Containers 2 0 212 B 212 B (100%)
Local Volumes 2 1 36 B 0 B (0%)
Documentation about it: https://docs.docker.com/engine/reference/commandline/system_df/
That could reclaim lots of space on your host machine, and will even give you a sum up of the amount of space it reclaims:
$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
f44f9b81948b3919590d5f79a680d8378f1139b41952e219830a33027c80c867
792776e68ac9d75bce4092bc1b5cc17b779bc926ab04f4185aec9bf1c0d4641f
Deleted Networks:
network1
network2
Deleted Images:
untagged: hello-world#sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
deleted: sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57
deleted: sha256:45761469c965421a92a69cc50e92c01e0cfa94fe026cdd1233445ea00e96289a
Total reclaimed space: 1.84kB
The most radical form of it being:
$ docker system prune --all --volumes
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all volumes not used by at least one container
- all images without at least one container associated to them
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
0998aa37185a1a7036b0e12cf1ac1b6442dcfa30a5c9650a42ed5010046f195b
73958bfb884fa81fa4cc6baf61055667e940ea2357b4036acbbe25a60f442a4d
Deleted Networks:
my-network-a
my-network-b
Deleted Volumes:
named-vol
Deleted Images:
untagged: my-curl:latest
deleted: sha256:7d88582121f2a29031d92017754d62a0d1a215c97e8f0106c586546e7404447d
deleted: sha256:dd14a93d83593d4024152f85d7c63f76aaa4e73e228377ba1d130ef5149f4d8b
untagged: alpine:3.3
deleted: sha256:695f3d04125db3266d4ab7bbb3c6b23aa4293923e762aa2562c54f49a28f009f
untagged: alpine:latest
deleted: sha256:ee4603260daafe1a8c2f3b78fd760922918ab2441cbb2853ed5c439e59c52f96
deleted: sha256:9007f5987db353ec398a223bc5a135c5a9601798ba20a1abba537ea2f8ac765f
deleted: sha256:71fa90c8f04769c9721459d5aa0936db640b92c8c91c9b589b54abd412d120ab
deleted: sha256:bb1c3357b3c30ece26e6604aea7d2ec0ace4166ff34c3616701279c22444c0f3
untagged: my-jq:latest
deleted: sha256:6e66d724542af9bc4c4abf4a909791d7260b6d0110d8e220708b09e4ee1322e1
deleted: sha256:07b3fa89d4b17009eb3988dfc592c7d30ab3ba52d2007832dffcf6d40e3eda7f
deleted: sha256:3a88a5c81eb5c283e72db2dbc6d65cbfd8e80b6c89bb6e714cfaaa0eed99c548
Total reclaimed space: 13.5 MB
Documentation could be found here: https://docs.docker.com/engine/reference/commandline/system_prune/

Related

Is there a way not to create dependant child images when building a docker container [duplicate]

When I run the docker-compose build command to rebuild an image in Docker because I had changed something in Dockerfile, sometimes I get "none" image tags. How can we avoid this fact? I want to rebuild the image but the none image should not appear.
REPOSITORY TAG IMAGE ID CREATED SIZE
magento2 latest b4dce4dcbd4f 16 hours ago 516MB
<none> <none> b4ffce2bf91e 16 hours ago 519MB
<none> <none> a1aedb60c82a 17 hours ago 516MB
<none> <none> ec9a14ae856c 20 hours ago 519MB
<none> <none> ef8eba6874cc 23 hours ago 516MB
<none> <none> 0e53a8b8c303 23 hours ago 516MB
php 7.1-apache 93e6fb4b13e1 3 weeks ago 369MB
mysql 5.6.39 079344ce5ebd 7 months ago 256MB
Below are some parts from What are Docker <none>:<none> images?
The Good <none>:<none>
These are intermediate images and can be seen using docker images -a. They don't result into a disk space problem but it is definitely a screen "real estate" problem. Since all these <none>:<none> images can be quite confusing as what they signify.
The Bad <none>:<none>
These images are the dangling ones, which can cause disk space problems. These <none>:<none> images are being listed as part of docker images and need to be pruned.
(a dangling file system layer in Docker is something that is unused and is not being referenced by any images. Hence we need a mechanism for Docker to clear these dangling images)
So,
if your case has to do with dangling images, it's ok to remove them with:
docker rmi $(docker images -f "dangling=true" -q)
There is also the option of docker image prune but the client and daemon API must both be at least v1.25 to use this command.
if your case has to do with intermediate images, it's ok to keep them, other images are pointing references to them.
Related documentation:
docker rmi
docker image rm
docker image prune
In my experience most of the <none> images are held by temporary containers. Due to Docker architecture those containers are preserved even after they stop. You can verify how many stopped containers you have using
docker ps -a
So to remove the <none> images you first need to remove the unneeded containers:
docker container prune
docker image prune
The above two commands can be abbreviated to
docker system prune
There is little to add based on what #tgogos said except that it needs more upvoting.
You can check image sizes of dangling and non-dangling images here:
docker system df -v
Don't be bugged by intermediate images. This way you oversee that the build process has been made more efficient by keeping intermediate images for each line of a Dockerfile, i.e. such a line can be skipped during the build process if no change occurred.
This will remove all dangling docker images in Windows:
for /f %x in ('docker images -f "dangling=true" -q') do docker rmi %x
You can remove dangling images using
docker rmi $(docker images -f "dangling=true" | grep "<none>.*<none>" | awk '{ print $3; }')
To remove <none> layers use:
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

Deleting the Docker disk image size

I'm using docker and I got an error "No space on the drive" when I tried to use the docker. So, I searched online and found that I had to remove the the unused images from the docker. So, I used the command
docker system prune --all
It deleted about ~30GB of the images. But When I run the docker again I got the same "No space" issue and when I checked the disk image size it showed me that 64 GB used even though I deleted the unused containers.
I had to increase the size of the drive every time when I use docker.
docker images output
REPOSITOY TAG IMAGE ID CREATED SIZE
postgres latest aal783da97 2 days ago 6.32GB
redis latest aal783da98 2 days ago 6.32GB
mysql latest aal783da99 2 days ago 6.32GB
airflow_worker latest aal783da91 2 days ago 6.32GB
airflow_scheduler latest aal783da92 2 days ago 6.32GB
How do I delete all the 64.1 GB?

Why the "none" image appears in Docker and how can we avoid it

When I run the docker-compose build command to rebuild an image in Docker because I had changed something in Dockerfile, sometimes I get "none" image tags. How can we avoid this fact? I want to rebuild the image but the none image should not appear.
REPOSITORY TAG IMAGE ID CREATED SIZE
magento2 latest b4dce4dcbd4f 16 hours ago 516MB
<none> <none> b4ffce2bf91e 16 hours ago 519MB
<none> <none> a1aedb60c82a 17 hours ago 516MB
<none> <none> ec9a14ae856c 20 hours ago 519MB
<none> <none> ef8eba6874cc 23 hours ago 516MB
<none> <none> 0e53a8b8c303 23 hours ago 516MB
php 7.1-apache 93e6fb4b13e1 3 weeks ago 369MB
mysql 5.6.39 079344ce5ebd 7 months ago 256MB
Below are some parts from What are Docker <none>:<none> images?
The Good <none>:<none>
These are intermediate images and can be seen using docker images -a. They don't result into a disk space problem but it is definitely a screen "real estate" problem. Since all these <none>:<none> images can be quite confusing as what they signify.
The Bad <none>:<none>
These images are the dangling ones, which can cause disk space problems. These <none>:<none> images are being listed as part of docker images and need to be pruned.
(a dangling file system layer in Docker is something that is unused and is not being referenced by any images. Hence we need a mechanism for Docker to clear these dangling images)
So,
if your case has to do with dangling images, it's ok to remove them with:
docker rmi $(docker images -f "dangling=true" -q)
There is also the option of docker image prune but the client and daemon API must both be at least v1.25 to use this command.
if your case has to do with intermediate images, it's ok to keep them, other images are pointing references to them.
Related documentation:
docker rmi
docker image rm
docker image prune
In my experience most of the <none> images are held by temporary containers. Due to Docker architecture those containers are preserved even after they stop. You can verify how many stopped containers you have using
docker ps -a
So to remove the <none> images you first need to remove the unneeded containers:
docker container prune
docker image prune
The above two commands can be abbreviated to
docker system prune
There is little to add based on what #tgogos said except that it needs more upvoting.
You can check image sizes of dangling and non-dangling images here:
docker system df -v
Don't be bugged by intermediate images. This way you oversee that the build process has been made more efficient by keeping intermediate images for each line of a Dockerfile, i.e. such a line can be skipped during the build process if no change occurred.
This will remove all dangling docker images in Windows:
for /f %x in ('docker images -f "dangling=true" -q') do docker rmi %x
You can remove dangling images using
docker rmi $(docker images -f "dangling=true" | grep "<none>.*<none>" | awk '{ print $3; }')
To remove <none> layers use:
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

REPOSITORY <none> TAG <none>

I am new here trying to learn docker, I started this tutorial
https://docs.docker.com/engine/examples/nodejs_web_app/
Building your image
$ docker build -t mlotfi/centos-node-hello .
mlotfi is my username in https://hub.docker.com/
when I did docker images, I got:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> sha256:189cb 27 seconds ago 485.1 MB
centos centos6 sha256:d0a31 12 days ago 228.9 MB
instead of:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mlotfi/centos-node-hello latest sha256:189cb 27 seconds ago 485.1 MB
centos centos6 sha256:d0a31 12 days ago 228.9 MB
UPDATE:
at the end of the build I see :
Complete!
---> e053d8f57e5c
Removing intermediate container 060f921fd08c
Step 4 : COPY package.json /src/package.json
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and
directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and r
eset permissions for sensitive files and directories.
lstat package.json: no such file or directory
But I already have package.json in the src directory.
That can happen if your docker build sequence does not got all the way, meaning it stops on error at some point in the Dockerfile.
The result of that interrupted process is the last intermediate image built by the Dockerfile line that succeeded, just before the Dockerfile line that fail to execute properly.
Other reasons are listed in "What are Docker <none>:<none> images? "
Each docker image is composed of layers, with these layers having a parent-child hierarchical relationship with each other.
All docker file system layers are by default stored at /var/lib/docker/graph. Docker calls it the graph database
<none>:<none> images stand for. They stand for intermediate images and can be seen using docker images -a.
Another style of <none>:<none> images are the dangling images which can cause disk space problems.
A dangling image and needs to be pruned. When our hello_world image was rebuilt using the Dockerfile, its reference to old Fedora became untagged and dangling.
you can see an example of dangling image in "What are <none> repository and tags? Why do they appear when I use docker build?".
The next command can be used to clean up these dangling images.
docker rmi $(docker images -f "dangling=true" -q)
In your case, if this was the first time your used docker build, this should not be a dangling image, but an intermediate one as I explained first in this answer.

If images in Docker are untagged, are they used at all or just orphans?

Running the commands docker images and docker images -a results in the following outputs:
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 9cbaf023786c 2 days ago 192.8 MB
$ docker images -a
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 9cbaf023786c 2 days ago 192.8 MB
<none> <none> 03db2b23cf03 2 days ago 192.8 MB
<none> <none> 8f321fc43180 2 days ago 192.8 MB
<none> <none> 6a459d727ebb 2 days ago 192.8 MB
<none> <none> 2dcbbf65536c 2 days ago 192.8 MB
<none> <none> 97fd97495e49 2 days ago 192.6 MB
Are the images tagged <none> of any importance? If not: why do they come with the tagged images I pulled? Do the sizes add up or are they just a repition? If so, can I delete them without any effect on my work?
The image files are independent, and combine via unionfs magic to form a running container.
The images you care about are often tagged with memorable names.
You can delete the unused images, i.e. those not contributing to any image you care about. I do it this way in bash:
function docker_rm_unnamed_images {
sudo docker rmi $(sudo docker images | grep '^<none>' | awk '{print $3}')
}
You can think of a docker image as a stack of 'layers'. Each Dockerfile command adds an additional layer to the image. It's important to realize that each of those commands creates a separate image file. So the Dockerfile
FROM foo
RUN a
RUN b
RUN c
would be a stack of
image=1 (possibly pulled from the foo registry)
image=2 (after applying a to image 1)
image=3 (after applying b to image 2)
image=4 (after applying c to image 3)
It is likely that the foo image was composed of multiple other layers, so your final image is a stack of 4 or more images. Each of those image files lives in your docker image registry. Most of them are unnamed, because they correspond to a RUN command, for example. Each of the image files 1-4 are probably fairly small (unless they correspond to a yum install p1 .. p100 for example). Together they make up the file system of the container that you ultimately run.
To remove all untagged images, the additional options is needed:
docker rmi $(sudo docker images -a | grep '^<none>' | awk '{print $3}')
option '-a': show all images, including untagged images

Resources