Skip to content

Instantly share code, notes, and snippets.

@mlgrm
Last active April 1, 2019 10:04
Show Gist options
  • Save mlgrm/8833e6241d6f29d851bb0e23a1fb7a84 to your computer and use it in GitHub Desktop.
Save mlgrm/8833e6241d6f29d851bb0e23a1fb7a84 to your computer and use it in GitHub Desktop.
# 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