Skip to content

Instantly share code, notes, and snippets.

@ioggstream
Created November 19, 2015 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioggstream/dc5716be7801894db335 to your computer and use it in GitHub Desktop.
Save ioggstream/dc5716be7801894db335 to your computer and use it in GitHub Desktop.
Docker shell profile.
dip(){
# Show docker ips
local arg=${1}
if [ -z "$arg" ]; then
arg=$(docker ps -q)
fi
/bin/docker inspect --format ' {{.Name}} {{.NetworkSettings.IPAddress}}' $arg
}
#
# Docker Exec alias with auto-complete
#
dshell(){
local container="$1"
local command="${2:-/bin/bash}"
/bin/docker exec -ti "$container" "$command"
}
_dshell()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="$(docker inspect -f '{{.Name}}' $(docker ps -q))"
opts=${opts//\/}
if [[ ${cur} =~ [a-z]+ ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _dshell dshell
dhown(){
# Set docker permissions and context to the current directory
sudo chgrp -R docker "$@"
sudo chcon -Rt svirt_sandbox_file_t "$@"
}
fig(){
/bin/docker-compose "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment