Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 135 lines (107 sloc) 1.98 KB
#!/bin/bash
function docker_killrm()
{
local liste=$@
if [ ! -z "$liste" ]; then
docker kill $liste 2>&1 | grep -v 'is not running'
docker rm -f $liste
fi
}
function docker_sweep()
{
local liste=$(docker ps --filter "status=exited" -q |xargs)
docker_killrm $liste
docker volume ls -qf dangling=true | xargs -r docker volume rm
}
function docker_cleanall()
{
local liste=$(docker ps -aq |xargs)
docker_killrm $liste
}
function docker_rmi_none()
{
liste=$(docker images -a | grep none | awk '{print $3}' |xargs)
if [ ! -z "$liste" ]; then
docker rmi $liste 2>&1 | grep -v "image has dependent child images"
fi
}
function docker_path()
{
local cnt=$1
cnt_id=$(docker inspect $cnt |grep Id | sed -e 's/.*: //g' -e 's/[",]//g')
mount_id=$(sudo cat /var/lib/docker/image/aufs/layerdb/mounts/$cnt_id/mount-id)
mount_path=/var/lib/docker/aufs/mnt/$mount_id
echo $mount_path
}
function docker_logs()
{
local cnt=$1
cnt_id=$(docker inspect $cnt |grep Id | sed -e 's/.*: //g' -e 's/[",]//g')
logs_path=/var/lib/docker/containers/$cnt_id/$cnt_id-json.log
sudo tail -f $logs_path
}
function docker_in()
{
docker exec -ti $1 bash
}
function docker_ipa()
{
docker exec $1 ip a
}
function docker_restart()
{
docker stop $1
docker restart $1
}
case $1 in
ip)
docker inspect --format '{{.NetworkSettings.IPAddress}}' $2
;;
clean)
docker_killrm $2
docker_rmi_none
;;
sweep)
docker_sweep
docker_rmi_none
;;
cleanall)
docker_cleanall
docker_rmi_none
;;
path)
docker_path $2
;;
in)
docker_in $2
;;
restart)
docker_restart $2
;;
resetrzo)
sudo service docker stop
sudo iptables -t nat -F
sudo ifconfig docker0 down
sudo brctl delbr docker0
sudo service docker start
;;
#test)
# while 1 do;
# docker_in $2
# docker_restart $2
# done
# ;;
ipa)
docker_ipa $2
;;
logs)
docker_logs $2
;;
reboot)
sudo systemctl stop docker
sudo ip link del docker0
sudo systemctl start docker
;;
*)
echo 'dock clean $vm|sweep|cleanall|resetrzo|ipa|logs|reboot'
esac