Last active
November 27, 2015 14:56
-
-
Save plesiv/2840b0e22b5fdab08ec0 to your computer and use it in GitHub Desktop.
Rudimentary functions for batch actions on docker containers / images (load, save, kill, remove)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# save all tagged Docker images in the current directory | |
svimgs() { local image_ids=$(docker images | tail -n+2 | awk '{print $1 ":" $2}'); for id in $image_ids; do cdir=$(dirname $id); mkdir -p $cdir; docker save -o $id $id; done } | |
# load in Docker all images from the current directory | |
ldimgs() { local image_files=$(find -type f); for file in $image_files; do docker load --input $file; done } | |
# remove all images from Docker | |
rmimgs() { docker rmi -f $(docker images | tail -n+2 | awk '{print $3}' | sort -u); } | |
# clean <none> images | |
cleanimgs() { docker rmi -f $(docker images | grep '<none>' | awk '{print $3}' | sort -u); } | |
# kill all containers | |
killcs() { docker kill $(docker ps -a | tail -n+2 | awk '{print $1}'); } | |
# restart all running containers | |
rstcs() { docker restart $(docker ps | tail -n+2 | awk '{print $1}'); } | |
# restart all containers | |
rstacs() { docker restart $(docker ps -a | tail -n+2 | awk '{print $1}'); } | |
# remove all containers | |
rmcs() { docker rm $(docker ps -a | tail -n+2 | awk '{print $1}'); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment