DEV Community

Cover image for #020 Docker cleaning up
Omar
Omar

Posted on • Edited on

#020 Docker cleaning up

Introduction

this is part 20 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


Cleaning

ps-a

Let's see how many stopped containers we have by using

docker ps -a
Enter fullscreen mode Exit fullscreen mode

We have a lot!

what about images?

images

docker image ls
Enter fullscreen mode Exit fullscreen mode

we see a lot of basically those none are failed building images and they are not being used by anything , they called dangling images.

to see how much docker using space we run

system-df

docker system df
Enter fullscreen mode Exit fullscreen mode

we can see it's taking 6.1GB lot of space

let's clean all images that are not used by containers and dangling , we run

prune

docker system prune
Enter fullscreen mode Exit fullscreen mode

some useful tags here :
-f used to force , so we don't get a prompt to delete (good for automation tools)
-a used to delete every things including used images.

I am going to use
prune-f

docker system prune -f
Enter fullscreen mode Exit fullscreen mode

we see it delete lot of things , cool!

image-ls

docker ps -a
docker image ls
Enter fullscreen mode Exit fullscreen mode

as we see we have no containers anymore all stopped
and all our images gone!

if you need only to stop containers .

docker-stop

docker container stop $(docker container ls -a -q)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)