Skip to content

Instantly share code, notes, and snippets.

@sjeandeaux
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sjeandeaux/b752e3d593ad6cdb2485 to your computer and use it in GitHub Desktop.
Save sjeandeaux/b752e3d593ad6cdb2485 to your computer and use it in GitHub Desktop.
Proxy and Dockerfile
#!/bin/bash
#Verify http_proxy if presents used else ping google.com
docker-proxy-in() {
if [ -z "$http_proxy" ] && ping -c 1 google.com > /dev/null ; then
cat ${1:-Dockerfile}
else
sed -e "/FROM/a\\
\\
ENV http_proxy=\"$http_proxy\" https_proxy=\"$https_proxy\" ftp_proxy=\"$ftp_proxy\" no_proxy=\"$no_proxy\"
" ${1:-Dockerfile}
#remove information proxy
echo 'ENV http_proxy="" https_proxy="" ftp_proxy="" no_proxy=*'
fi
}
#Verify http_proxy if presents used else ping google.com
docker-proxy-file() {
if [ -z "$http_proxy" ] && ping -c 1 google.com > /dev/null ; then
echo ${1:-Dockerfile}
else
local file=${1:-Dockerfile}.proxy
sed "/FROM/a\\
\\
ENV http_proxy=\"$http_proxy\" https_proxy=\"$https_proxy\" ftp_proxy=\"$ftp_proxy\" no_proxy=\"$no_proxy\"
" ${1:-Dockerfile} > $file
echo 'ENV http_proxy="" https_proxy="" ftp_proxy="" no_proxy=*' >> $file
echo $file
fi
}

Dockerfile and Proxy

Use with docker

source docker-proxy.sh

#If we use Dockerfile without ADD with context path
docker-proxy-in Dockerfile | docker build -
docker-proxy-in | docker build -

#else
docker build -f `docker-proxy-file`
docker build -f `docker-proxy-file Dockerfile`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment