-
-
Save henrikuittinen/e294be6370d3143fcbce45d21b893708 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 sh -c '/bin/bash || /bin/sh' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment