Skip to content

Instantly share code, notes, and snippets.

@henrikuittinen
Forked from jaamo/dockerbash
Last active April 26, 2016 07:45
Show Gist options
  • Save henrikuittinen/e294be6370d3143fcbce45d21b893708 to your computer and use it in GitHub Desktop.
Save henrikuittinen/e294be6370d3143fcbce45d21b893708 to your computer and use it in GitHub Desktop.
Shortcut to execute docker exec -it ID bash
#!/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