Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 31 lines (20 sloc) 725 Bytes
#!/usr/bin/env bash
# docker-shellin: use `selecta` to select a running docker container and `docker exec`
# to spawn an interactive shell in it.
set -euo pipefail
function die {
echo "Error: $*" >&2
exit 1
}
function installed {
cmd=$(command -v "${1}")
[[ -n "${cmd}" ]] && [[ -f "${cmd}" ]]
return ${?}
}
CONTAINER_SHELL="${CONTAINER_SHELL:-bash}"
installed selecta || die "Requires selecta"
installed docker || die "Requires docker"
images=$(docker ps --format "{{.ID}} {{.Image}} {{.Names}}")
[[ -n "${images}" ]] || { echo "No running containers to select from."; exit; }
image=$(selecta <<< "${images}" | awk '{ print $1 }')
[[ -n "${image}" ]] && docker exec -it "${image}" "${CONTAINER_SHELL}"