Created
April 26, 2016 07:18
-
-
Save jaamo/15eacfa32c8051b0e9567672799c1b65 to your computer and use it in GitHub Desktop.
Shortcut to execute docker exec -it ID bash
This file contains 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
#!/bin/bash | |
# Print out a list of docker containers. | |
i=0 | |
firstrun=0 | |
while read x | |
do | |
if [ $firstrun == 0 ] | |
then | |
echo "$x" | |
else | |
echo "[$i] $x" | |
i=$((i+1)) | |
fi | |
firstrun=1 | |
done << EOF | |
$(docker ps) | |
EOF | |
# Ask for container index | |
read container_index | |
# Get requested container id | |
i=0 | |
container_id="" | |
for x in `docker ps -q` | |
do | |
if [ $container_index == $i ] | |
then | |
container_id=$x | |
fi | |
i=$(($i+1)) | |
done | |
# Run bash. | |
docker exec -it $container_id bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you change the last line to this, it would fall back to shell if bash is not available (some containers don't have bash)
docker exec -it $container_id sh -c '/bin/bash || /bin/sh'