Skip to content

Instantly share code, notes, and snippets.

@ljonesfl
Last active February 9, 2020 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljonesfl/256f7a0f1eaaf7dc4cef596315af6895 to your computer and use it in GitHub Desktop.
Save ljonesfl/256f7a0f1eaaf7dc4cef596315af6895 to your computer and use it in GitHub Desktop.
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
@hakobyansen
Copy link

hakobyansen 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