Skip to content

Instantly share code, notes, and snippets.

@Johnz86
Created April 6, 2018 13:32
Show Gist options
  • Save Johnz86/c031876321b0e89a64767dc201d98822 to your computer and use it in GitHub Desktop.
Save Johnz86/c031876321b0e89a64767dc201d98822 to your computer and use it in GitHub Desktop.
Setting up docker-machine proxy on the fly for gitbash under windows 7.
http_proxy=http://194.138.0.3:9400
https_proxy=http://194.138.0.3:9400
#!/bin/bash
#usage: source ./tasks/docker-setting.sh
echo "Setting environment variables in bash for default docker machine"
echo -en "\n"
eval "$(docker-machine env default --shell sh/bash)"
#!/bin/bash
[ -z ${DOCKER_HOST} ] && source ./tasks/default-docker-setting.sh
restart=
function docker_export_command {
echo "echo 'export $1' >> /var/lib/boot2docker/profile"
}
function docker_add_env {
echo "add missing env to default docker-machine"
docker-machine ssh default "sudo sh -c \"$(docker_export_command $1)\""
}
function docker_check_env {
docker-machine ssh default "grep -xq 'export ${1}' /var/lib/boot2docker/profile && echo 0 || echo 1"
}
function docker_add_environment_variable {
echo "check if default docker-machine has env $1"
if [ $(docker_check_env $1) -eq 1 ]; then
docker_add_env $1
restart=yes
fi
}
function docker_config_environment {
while IFS='' read -r line || [[ -n "$line" ]]; do
docker_add_environment_variable $line < /dev/null
done < $1
}
docker_config_environment ./tasks/.env.local
[ -z $restart ] && echo "docker-machine default proxy is already set" || docker-machine restart default
[[ $no_proxy == *"$(docker-machine ip default)"* ]] && echo "no_proxy for docker-machine ip default is set" || export no_proxy=$no_proxy,$(docker-machine ip default)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment