0

I've got a django project with docker and i've discovered that my docker folder eating space abnormally.

here is console:

[root@1507191 django]# docker images -a
REPOSITORY             TAG              IMAGE ID       CREATED        SIZE
django-web             latest           1ed6e146c8f1   12 days ago    5.98GB
postgres               13.9-alpine      8e750948d39a   6 months ago   238MB
selenium/node-chrome   4.7.2-20221219   de92c5f8374c   7 months ago   1.3GB
selenium/hub           4.7.2-20221219   cfb1e9a75197   7 months ago   420MB
nginx                  1.13-alpine      ebe2c7c61055   5 years ago    18MB

So docker folder should takes about 8GB but it takes 14GB:

[root@1507191 django]# pwd
/var/lib/docker
[root@1507191 django]# sudo du -d 1
4   ./swarm
28  ./volumes
9980    ./image
13028   ./buildkit
16  ./plugins
312 ./containers
13920928    ./overlay2
4   ./runtimes
80  ./network
4   ./tmp
13944392    .

So the question is: how to clean it safe?

Yuretz
  • 49
  • 8
  • 1
    Does this answer your question? [Does Docker purge old/unused images?](https://stackoverflow.com/questions/30313806/does-docker-purge-old-unused-images) – Botje Aug 04 '23 at 07:45
  • Thanks, but it's not a safe way: # docker rm $(sudo docker ps -a -q) 8c89711f8efb d3dbb5027e31 Error response from daemon: You cannot remove a running container 8ec93867b37c682146f61e3c5de28b4c92eb2bf1c2e219faa91ad8ea5c1ff832. Stop the container before attempting removal or force remove Error response from daemon: You cannot remove a running container b42d8591cb0b5a1d8e9c779b6442c3066cca866bef940f44d6cbb33a597da061. Stop the container before attempting removal or force remove Error response from daemon: You cannot remove a running container c14c0d1d35486518bc1cc1d605d116 – Yuretz Aug 04 '23 at 07:49
  • As with all advice on the internet, you need to read and understand everything before trying it. You get a warning for all running containers, that is true. But all dead containers will be removed by that `docker rm` call, such that `docker rmi` has a maximal chance of removing unused container images – Botje Aug 04 '23 at 07:53

1 Answers1

1

To clean Docker from unused stuff run one command docker system prune --all --volumes.

It will delete followings:

docker system prune -a --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
Justinas
  • 41,402
  • 5
  • 66
  • 96