Last active
April 1, 2019 10:04
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
# usage: curl -sL bit.ly/mlgrm-docker-remote | tail -n +3 >> $HOME/.bashrc && . $HOME/.bashrc | |
# --------- begin mlgrm docker_host function -------- # | |
# set environment variables to execute docker commands using gcp compute engine HOST | |
# leave out host to unset the variables | |
# usage docker_host HOST | |
docker_host () { | |
if [[ -n $1 ]]; then | |
export DOCKER_HOST="tcp://$(gcloud compute instances describe $1 \ | |
--format 'value(networkInterfaces[0].accessConfigs[0].natIP)'):2376" DOCKER_TLS_VERIFY=1 | |
if ! [[ -d $HOME/.docker && $(ls $HOME/.docker/{ca,cert,key}.pem | wc -l) -eq 3 ]]; then | |
>&2 echo "need to get the pem files and put them in ~/.docker. (maybe saved in drive as $1-tls.tgz?)" | |
fi | |
else | |
unset DOCKER_HOST DOCKER_TLS_VERIFY | |
fi | |
} | |
remove_docker_host () { | |
begin='# --------- begin mlgrm docker_host function -------- #' | |
end='# ---------- end mlgrm docker_host function ----------#' | |
sed "/^$begin$/,/^$end$/d" -i $HOME/.bashrc | |
} | |
# ---------- end mlgrm docker_host function ----------# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment