Skip to content

Instantly share code, notes, and snippets.

@robbanl
Last active April 6, 2018 06:17
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 robbanl/05577a4192148ee1144f1d196cccddb7 to your computer and use it in GitHub Desktop.
Save robbanl/05577a4192148ee1144f1d196cccddb7 to your computer and use it in GitHub Desktop.
Quick Docker Exec to bash
#!/bin/sh
# Feel free to create a bash alias to this file or place it in /usr/local/bin
#
# Usage: dex php to run "bash" in interactive mode on any container that contains php in it's name
CONTAINER="$(docker ps -f name=$1 | sed -n 2p)"
CONTAINER_NAME=`echo $CONTAINER | awk '{ print $NF }'`
# Make sure some argument is set
if [ -z "$1" ]; then
echo "Missing argument 1 with container name"
exit 1
fi
# Make sure something was found
if [ -z "$CONTAINER_NAME" ]; then
echo "No container found!\n";
docker ps
exit 1
fi
# Execute bash in interactive mode on the container
echo "Enterering $CONTAINER_NAME..."
docker exec -it $CONTAINER_NAME bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment