Created
March 6, 2017 15:14
-
-
Save Nikasa1889/5e470bb528166a1edd5f36ae8e265fab to your computer and use it in GitHub Desktop.
Bash script to open bash shell on a running docker
This file contains hidden or 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 | |
#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