I have a Linux system where I run docker. This system can only access the internet via corporate proxy.
For docker run I had to set the proxy config in my ~/.docker/config.json:
{
"proxies": {
"default": {
"httpProxy": "...",
"httpsProxy": "...",
"noProxy": "..."
}
}
}
To use proxy in docker build I had to set env vars in /etc/sysconfig/docker:
HTTP_PROXY="..."
HTTPS_PROXY="..."
NO_PROXY="..."
This system works fine and I can run docker run and docker build, both using the proxy settings.
Now I want to run my local docker on MacOS against this remote machine via docker context.
I created a context that connects via ssh to the remote host:
docker context create remote \
--description "remote execution" \
--docker "host=ssh://docker.remote"
I also set the proxy settings in my local ~/.docker/config.json:
{
"proxies": {
"remote": {
"httpProxy": "...",
"httpsProxy": "...",
"noProxy": "..."
}
}
}
A docker info shows the proxy is used and for docker run that also is true and I can access the internet from within containers.
Any attempt to access the internet though fails when calling docker build.
Is there some other file I need to change, just like the sysconfig file on linux?
I do have an ugly workaround now. I found that setting the proxy via --build-arg acutally works. To not always have to set the --build-args manually, I added an override for the docker command in my .bashrc. Ugly but working.
function docker {
if [ "$1" == "build" ] && [ "$#" -gt 1 ]; then
echo "Building with proxy!"
/usr/local/bin/docker "$@" \
--build-arg http_proxy="..." \
--build-arg https_proxy="..." \
--build-arg no_proxy="..."
else
/usr/local/bin/docker "$@"
fi
}
It seems an issue with docker backward compatibility with older versions settings, I've tried every single solution online for setting a proxy that affects
docker buildcommand, the only thing that worked for me:Purge every thing, NOTE that you will lose all your local images, containers, volumes.
After docker restarts set the proxy from Docker Desktop in
Settings > Resources > Proxies, and it will take effect.But I can't risk losing my data
the tedious solution unfortunately is setting
HTTP_PROXY&HTTPS_PROXYenv variables for every terminal session/process before executing docker commands:Mac / Linux:
Windows: