Skip to content

Instantly share code, notes, and snippets.

@h-mochizuki
Created February 19, 2020 08:21
Show Gist options
  • Save h-mochizuki/73d91e54862b88e2274353104765bdde to your computer and use it in GitHub Desktop.
Save h-mochizuki/73d91e54862b88e2274353104765bdde to your computer and use it in GitHub Desktop.
Dockerのプロセスとかイメージとか全部消す
@echo off
setlocal EnableDelayedExpansion
set "TARGETS="
for /f "usebackq tokens=*" %%i in ( `docker ps -q` ) do set "TARGETS=!TARGETS! %%i"
if not "x!TARGETS!"=="x" if not "x!TARGETS: =!"=="x" docker kill !TARGETS!
docker system prune -f
set "DANG_TARGETS="
set "TARGETS="
for /f "usebackq tokens=*" %%i in ( `docker images -f "dangling=true" -q` ) do set "DANG_TARGETS=!DANG_TARGETS! %%i"
for /f "usebackq tokens=*" %%i in ( `docker images --format "{{.Repository}}:{{.Tag}}"` ) do set "TARGETS=!TARGETS! %%i"
echo dang_target: !DANG_TARGETS!
echo target: !TARGETS!
if not "x!DANG_TARGETS!"=="x" if not "x!DANG_TARGETS: =!"=="x" echo !DANG_TARGETS! | each docker rmi {}
if not "x!TARGETS!"=="x" if not "x!TARGETS: =!"=="x" echo !TARGETS! | each docker rmi {}
docker volume prune -f
docker system prune -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment