Created
April 4, 2018 09:49
-
-
Save prozz/8bdda7bcc12db7b877f9014ffae2eab9 to your computer and use it in GitHub Desktop.
run bash in docker container matching given string
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 | |
name="${1?needs one argument}" | |
containerId=$(docker ps | grep $name | grep -o '^\w\+') | |
if [ $(echo $containerId | wc -w) -gt 1 ]; | |
then | |
echo "Multiple docker containers found for: $name" | |
exit 1 | |
fi | |
if [[ -n "$containerId" ]]; then | |
docker exec -it $containerId /bin/bash | |
else | |
echo "No docker container with name: $name is running" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment