Last active
December 5, 2023 13:13
-
-
Save dullage/ac87200410c20377824b193bfaba1036 to your computer and use it in GitHub Desktop.
Quickly open shell access to a running docker container. Usage: dockr [container name].
This file contains hidden or 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
#!/usr/bin/env bash | |
base_command="docker exec -it" | |
shells=(/bin/bash /bin/ash /bin/sh) | |
if [[ $1 == "" ]] | |
then | |
printf "Usage: dockr [container name]\n" | |
exit 1 | |
fi | |
for shell in ${shells[@]} | |
do | |
printf "Trying $shell..." | |
if docker exec $1 [ -f $shell ] | |
then | |
printf "ok\n" | |
$base_command $1 $shell | |
break | |
fi | |
printf "not found.\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also see the accompanying Bash completion script here: https://gist.github.com/Dullage/09905072df9f948f61cad10e9d8183c6