Created
May 25, 2021 04:47
-
-
Save tomsing1/322638b66bd793bc612743fa508eced5 to your computer and use it in GitHub Desktop.
Use mosh to log into a running docker-machine instance
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
| #!/usr/bin/env bash | |
| # This script provisions an EC2 instance via docker-machine and takes the | |
| # following positional arguments | |
| # 1. docker-machine name (bioinfo-sandmann) | |
| # 2. login username (ubuntu) | |
| set -e # exit upon error | |
| set -o nounset # no unset variables | |
| # global variables | |
| declare -r ACTIVE_MACHINE="${1:-bioinfo-sandmann}" | |
| declare -r INSTANCE_USERNAME="${2:-ubuntu}" | |
| declare ACTIVE_IP="$(docker-machine ip ${ACTIVE_MACHINE})" | |
| # check if mosh is already install on the server or install it | |
| docker-machine ssh "${ACTIVE_MACHINE}" -- which mosh &>/dev/null || \ | |
| docker-machine ssh "${ACTIVE_MACHINE}" -- apt-get install -y mosh | |
| # connect to the instance using mosh | |
| mosh --ssh \ | |
| "ssh -i ~/.docker/machine/machines/"${ACTIVE_MACHINE}"/id_rsa" "${INSTANCE_USERNAME}@${ACTIVE_IP}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment