Skip to content

Instantly share code, notes, and snippets.

@prozz
Created April 4, 2018 09:49
Show Gist options
  • Save prozz/8bdda7bcc12db7b877f9014ffae2eab9 to your computer and use it in GitHub Desktop.
Save prozz/8bdda7bcc12db7b877f9014ffae2eab9 to your computer and use it in GitHub Desktop.
run bash in docker container matching given string
#!/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