How to clear Docker machine on Windows

Mon, 08 Oct 2018

A few intensive hours building Docker containers quickly used up all the allocated space.

Deleting Docker images can be done using

docker images
docker rmi <IMAGE_ID> -f

Using -f to force deletion of images that are used in other containers that remain.

Deleting Docker containers:

docker ps
docker rm <CONTAINER_ID>

Easy right?

What if you got tens of images? Still easy.

Create a docker-rmi.bat and place the following contents

@echo off
FOR /f "tokens=\*" %%i IN ('docker images --format "{{.ID}}"') DO docker rmi %%i

For only clearing the containers the solution is similar (docker-containers-rm.bat):

@echo off
FOR /f "tokens=\*" %%i IN ('docker ps -aq') DO docker rm %%i

Run the .bat executables in CMD and you're doney.

Thanks to daredude!

Categories: docker, how-to