Reputation: 413
I am attempting to cleanup a (Windows) build server we use with our containers.
My goal is to periodically remove everything that isn't a base image, and I am doing this by filtering on our private registry name. I am running into this weird error when I try to use PowerShell for this:
PS C:\> docker images | Select-String "azurecr" | % { docker rmi $_ }
Error response from daemon: invalid reference format: repository name must be lowercase
Error response from daemon: invalid reference format: repository name must be lowercase
Error response from daemon: invalid reference format: repository name must be lowercase
Error response from daemon: invalid reference format: repository name must be lowercase
Error response from daemon: invalid reference format: repository name must be lowercase
Here is me just running the Select-String
filter on its own, which returns the images without issue:
docker images | Select-String "azurecr"
Despite what the error states, there are no uppercase characters in the registry or image name.
Also not working:
PS C:\> (docker images) -like '*azurecr*' | % { docker rmi $_ }
Error response from daemon: invalid reference format: repository name must be lowercase
Error response from daemon: invalid reference format: repository name must be lowercase
Error response from daemon: invalid reference format: repository name must be lowercase
Upvotes: 0
Views: 3099
Reputation: 200273
Use the -like
operator for filtering the docker images
output. Not only is it more lightweight than Select-String
, but the latter also produces MatchInfo
objects rather than passing just the matched strings through, which might cause undesired behavior. Also, you cannot just pass the full lines to docker rmi
. The command expects an image ID, so you need to extract that from the string.
(docker images) -like '*azurecr*' | ForEach-Object {
$id = ($_ -split '\s+')[2]
docker rmi $id
}
Upvotes: 3