Skip to content

Instantly share code, notes, and snippets.

@Nikasa1889
Created March 6, 2017 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikasa1889/5e470bb528166a1edd5f36ae8e265fab to your computer and use it in GitHub Desktop.
Save Nikasa1889/5e470bb528166a1edd5f36ae8e265fab to your computer and use it in GitHub Desktop.
Bash script to open bash shell on a running docker
#!/bin/bash
#List current running docker images
echo "Select one of the following running images:"
echo -e "Number \t Name"
echo $(docker ps | tail -n +2| awk -F ' ' '{printf("%7d %s\n", NR, $2)}')
read -p "Enter the process number:" selectedID
selectedID=$(($selectedID + 1))
#Get Docker process ID of the specified docker image name
DOCKER_ID=$(docker ps | tail -n +$selectedID | head -1 | awk '{print $1}')
docker exec -it $DOCKER_ID /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment