Skip to content

Instantly share code, notes, and snippets.

@dullage
Last active December 5, 2023 13:13
Show Gist options
  • Save dullage/ac87200410c20377824b193bfaba1036 to your computer and use it in GitHub Desktop.
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].
#!/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
@dullage
Copy link
Author

dullage commented Sep 4, 2020

Also see the accompanying Bash completion script here: https://gist.github.com/Dullage/09905072df9f948f61cad10e9d8183c6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment