[Powershell]Clear docker images by Invoke-RestMethod to docker api

# Clear expired docker images with in specific namespace (30 days ago)
(Invoke-RestMethod http://localhost:2375/images/json) | Where-Object { $_.RepoTags -Like '*/q1game/*' -And ((New-TimeSpan -Start (Get-Date '1970-1-1') -End (Get-Date).ToUniversalTime()).TotalSeconds - $_.Created) -GT (30 * 24 * 60 * 60)} | ForEach-Object{ docker.exe rmi $_.RepoTags }

Leave a Comment