-
-
Save theodorosploumis/10870cc863e65044abd849db67eff615 to your computer and use it in GitHub Desktop.
dockr - some useful docker shortcuts
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
#!/bin/bash | |
# add yourself to the docker group | |
# useradd -G docker USERNAME | |
# then you can enjoy this (for instance) | |
# dockr get logstash_container ip - to get the ip of the container | |
# or | |
# dockr stop last - to stop the last container you ran | |
# or | |
# dockr rmi none - to remove all <none> images | |
if [ "$1" == "ps" ]; then | |
docker ps | |
elif [ "$1" == "psa" ]; then | |
docker ps -a | |
elif [ "$1" == "img" ]; then | |
docker images | |
elif [ "$1" == "stop" ]; then | |
container=$2 | |
if [ "${container}" == "last" ]; then | |
container=$(docker ps -lq) | |
fi | |
docker stop ${container} | |
elif [ "$1" == "rm" ]; then | |
if [ "$2" == "all" ]; then | |
docker rm -f $(docker ps -a -q) | |
else | |
docker rm -f $2 | |
fi | |
elif [ "$1" == "rmi" ]; then | |
if [ "$2" == "none" ]; then | |
docker rmi -f $(docker images | grep "^<none>" | awk '{print $"3"}') | |
elif [ "$2" == "all" ]; then | |
docker images -a -q | xargs -n 1 -I {} docker rmi {} | |
else | |
docker rmi -f $2 | |
fi | |
elif [ "$1" == "get" ]; then | |
container=$2 | |
if [ "${container}" == "last" ]; then | |
container=$(docker ps -lq) | |
fi | |
if [ "$3" == "ip" ]; then | |
docker inspect -f "{{ .NetworkSettings.IPAddress }}" ${container} | |
elif [ "$3" == "links" ]; then | |
docker inspect -f "{{ .HostConfig.Links }}" ${container} | |
elif [ "$3" == "env" ]; then | |
docker inspect -f "{{ .Config.Env }}" ${container} | |
elif [ "$3" == "cmd" ]; then | |
docker inspect -f "{{ .Config.Cmd }}" ${container} | |
elif [ "$3" == "volf" ]; then | |
docker inspect -f "{{ .HostConfig.VolumesFrom }}" ${container} | |
elif [ "$3" == "vols" ]; then | |
docker inspect -f "{{ .Volumes }}" ${container} | |
else | |
docker inspect ${container} | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment