Last active
April 6, 2018 06:17
-
-
Save robbanl/05577a4192148ee1144f1d196cccddb7 to your computer and use it in GitHub Desktop.
Quick Docker Exec to bash
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/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