Skip to content

Instantly share code, notes, and snippets.

@nir0s
Created January 21, 2015 19:04
Show Gist options
  • Save nir0s/89c1c98b7406c36089f5 to your computer and use it in GitHub Desktop.
Save nir0s/89c1c98b7406c36089f5 to your computer and use it in GitHub Desktop.
dockr - some useful docker shortcuts
#!/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