Skip to content

Instantly share code, notes, and snippets.

@ljonesfl ljonesfl/d-s.sh
Last active Feb 9, 2020

Embed
What would you like to do?
Shell into a docker container ./d-s.sh image-name
#!/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
@c0d3b0t

This comment has been minimized.

Copy link

c0d3b0t commented Feb 9, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.