Skip to content

Instantly share code, notes, and snippets.

@jakebathman
Last active May 8, 2019 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebathman/2aee2797f8cda12ce81ffd35f220b0f7 to your computer and use it in GitHub Desktop.
Save jakebathman/2aee2797f8cda12ce81ffd35f220b0f7 to your computer and use it in GitHub Desktop.
"SSH" into one of your running docker containers
#! /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
@jakebathman
Copy link
Author

This is just a quick comment 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment