Last active
February 9, 2020 18:52
-
-
Save ljonesfl/256f7a0f1eaaf7dc4cef596315af6895 to your computer and use it in GitHub Desktop.
Shell into a docker container ./d-s.sh image-name
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 | |
echo "Looking for $1" | |
OUT="$(docker ps | awk '{if( $2==container ) print $1}'-v container=$1)" | |
if [ ${#OUT} -eq 0 ] | |
then | |
echo "Unable to locate a container running the image $1" | |
exit 1 | |
fi | |
echo "Executing shell for Container ID:${OUT} running image $1" | |
docker exec -it ${OUT} bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make the
d-s
command to be available globally:chmod +x d-s.sh
sudo mv d-s.sh /usr/local/bin/d-s
And use it:
d-s image-name