Last active
May 8, 2019 15:48
-
-
Save jakebathman/2aee2797f8cda12ce81ffd35f220b0f7 to your computer and use it in GitHub Desktop.
"SSH" into one of your running docker containers
This file contains hidden or 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/bash | |
## Setup note: | |
## Add execution permissions to this file using: | |
## chmod u+x dssh.sh | |
unset options i o | |
opt=( $(docker ps --format '{{.Names}}' | sort | awk '{print v++,$1}') ) | |
# Show the user a list of containers to pick from | |
container=$(dialog --title "Choose a Docker Container" --menu "\"SSH\" into..." 15 55 10 "${opt[@]}" 3>&1 1>&2 2>&3 3>&- ) | |
if [ -z "$container" ]; then | |
clear && exit 1; | |
fi | |
# Get the container name from the selection | |
opt_index=$(($container * 2 + 1)) | |
container_name="${opt[$opt_index]}" | |
# "ssh" into it | |
clear && docker exec -it "$container_name" bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just a quick comment 👍