Skip to content

Instantly share code, notes, and snippets.



Last active Apr 6, 2018
What would you like to do?
Quick Docker Exec to bash
# 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
# Make sure something was found
if [ -z "$CONTAINER_NAME" ]; then
echo "No container found!\n";
docker ps
exit 1
# 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