Here's a bash script to quickly login into a docker container


« Back to overview

This script allows you to quickly login into a docker container.
It lists all available containers, and prompts you for part of the container name.

It then opens a shell into that container.


/usr/local/bin/d-shell:
#!/bin/bash
# list docker containers and allows to login
echo "Select a docker container by part of it's name to open a shell into:"
echo ""

docker ps
echo ""
echo "Part of the container name to login to:"
read _name

containers=$(docker ps -aqf "name=$_name")
container=$(echo $containers | awk '{print $1;}') 
echo ""

if [ -z "$container" ]; then
    echo "no container found"
    exit
fi

echo "Logging into $container"
docker exec -it $container /bin/sh