Last active
April 8, 2018 07:01
-
-
Save Fusion/a441a1ad4556de631f5d89e403ed8f53 to your computer and use it in GitHub Desktop.
Start SSH access for container (helpful to mount container's root volume remotely over sshfs)
This file contains 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
bash | |
if [ -z "$(which dialog)" ]; then sudo apt-get update && sudo apt-get install -y dialog; fi \ | |
&& dialog --menu 'Pick container to instrument' 20 79 20 $(docker ps --format '{{.ID}} {{.Names}}') 2>/tmp/dialog.pick \ | |
&& C="$(cat /tmp/dialog.pick)" \ | |
&& if [ -z "$C" ]; then exit 0; fi \ | |
&& if [ -z "$(docker exec -t ${C} find /etc -name alpine-release)" ]; then | |
CU='apt-get'; CI='apt-get install -y'; else CU='apk'; CI='apk add'; fi \ | |
&& if [ -z "$(docker exec -t ${C} which dropbear)" ]; then docker exec -t ${C} sh -c "${CU} update && ${CI} dropbear openssh-sftp-server && mkdir /etc/dropbear && dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key"; fi \ | |
&& docker exec -it ${C} passwd |
This file contains 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
sshfs -p PORT root@HOST ./MOUNT |
This file contains 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
bash | |
dialog --menu 'Pick container to access' 20 79 20 $(docker ps --format '{{.ID}} {{.Names}}') 2>/tmp/dialog.pick \ | |
&& C="$(cat /tmp/dialog.pick)" \ | |
&& if [ -z "$C" ]; then exit 0; fi \ | |
&& P1=$(netstat -plnt 2>/dev/null | grep -Po '(222[0-9]{2})' | sort | tail -1) && P2=${P1:-22199} && PORT=$((P2 + 1)) \ | |
&& IP=$((docker exec -t ${C} ip addr) | grep -Po '((172|10)\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' | grep -v '255\.255') \ | |
&& docker run -l io.rancher.container.network=true -d ${RM} --name ssher-${PORT} -p ${PORT}:${PORT} svendowideit/ambassador ${IP} ${PORT} \ | |
&& docker exec -t ${C} dropbear -p ${PORT} |
This file contains 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
bash | |
dialog --menu 'Pick container to lock' 20 79 20 $(docker ps --format '{{.ID}} {{.Names}}') 2>/tmp/dialog.pick \ | |
&& C="$(cat /tmp/dialog.pick)" \ | |
&& if [ -z "$C" ]; then exit 0; fi \ | |
&& PORTCMD=$(docker exec -t ${C} ps ax | grep dropbear | tr -d "\r") \ | |
&& PORT="${PORTCMD##* }" \ | |
&& dialog --inputbox 'Select gateway' 10 10 ssher-${PORT} 2>/tmp/dialog.pick \ | |
&& GWP="$(cat /tmp/dialog.pick)" \ | |
&& if [ -z "$PORT" ]; then exit 0; fi \ | |
&& docker stop ${GWP} && docker rm ${GWP} && docker exec -t ${C} killall dropbear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works with Docker, local Swarm, local Rancher