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.

# 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"

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