Lee
Lee

Reputation: 1171

Docker cannot remove all images

i'm using Docker Desktop for Windows. When I try to remove all of my images by this command:

docker rmi $(docker images -q)

I got this error message in command prompt:

unknown shorthand flag: 'q' in -q)

I'm running Docker on Window 10 Pro

Upvotes: 4

Views: 3579

Answers (9)

veben
veben

Reputation: 22292

You forgot the -a. To delete all the images, use this:

docker image prune -a -f

And remember that you have to remove all the associated containers before removing all the images.

To delete all containers in use:

docker container prune -f

Upvotes: 0

schlicki
schlicki

Reputation: 374

Old question, but if you are on Windows switch from the cmd to PowerShell. cmd is misinterpreting some commands and tries to attach the -q to the outter rmi command.

Upvotes: 2

Santiago Álvarez
Santiago Álvarez

Reputation: 41

Save this in docker-clear.bat and execute to clear containers, images, unused data and volumes

@echo off
REM Clear all the containers
FOR /f "tokens=*" %%i IN ('docker ps -aq') DO docker stop %%i && docker rm %%i
REM Clear all the images
FOR /f "tokens=*" %%i IN ('docker images --format "{{.ID}}"') DO docker rmi %%i -f
REM Clear unused data
docker system prune -f
REM Clear all volumes
docker volume prune -f

Upvotes: 0

Tim Maes
Tim Maes

Reputation: 612

Windows 10 Powershell, it is easy.

Following command shows all images:

docker -a -q

outputs this:

PS C:\Users\UserName> docker images -a -q
86fa138dd93d
7c3a8b83a719
6636e7059d8d

then, for each image do

docker rmi ##########

Where ##### is the image id

Upvotes: 0

herm
herm

Reputation: 16315

Use the docker system prune -a or docker image prune -a commands to delete any unused or dangling images.

Upvotes: 1

javasenior
javasenior

Reputation: 1815

Syntax is unix specific, so you change your command for Windows and you'll need to run the whole command in PowerShell or CMD.

remove containers:

powershell "docker ps -a -q | foreach-object { $i = $PSItem.ToString(); $cmd = 'docker'; & $cmd 'rm' '-f' $i }"

remove images:

powershell "docker images -a -q | foreach-object { $i = $PSItem.ToString(); $cmd = 'docker'; & $cmd 'rmi' '-f' $i }"

Upvotes: 5

BMitch
BMitch

Reputation: 263726

That's a bash shell syntax which would work on Linux installs of docker. To get it to work on Windows, try installing the bash shell on Windows and running it from inside that shell. The Windows command prompt and powershell won't understand that syntax.

Upvotes: 0

evgenyl
evgenyl

Reputation: 8107

In the windows, you should windows command.

In powershell, it'll be something like:

docker images -a -q | foreach-object { $i = $PSItem.ToString(); $cmd = "docker"; & $cmd "rmi" $i }

Where

docker images -a -q

gets the IDs of all images (including intermediate), and

foreach-object { $i = $PSItem.ToString(); $cmd = "docker"; & $cmd "rmi" $i }

delete them one-by-one

Upvotes: 0

GauravJ
GauravJ

Reputation: 2262

Look at similar issue. The syntax you are using is unix specific docker rmi $(command). This is called command substitution and probably will not work in windows.

Upvotes: 0

Related Questions