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