Skip to content

Instantly share code, notes, and snippets.

@vladak
Last active May 27, 2021 15:26
Show Gist options
  • Save vladak/b13d19a89af9b7249226d2c54f52dd28 to your computer and use it in GitHub Desktop.
Save vladak/b13d19a89af9b7249226d2c54f52dd28 to your computer and use it in GitHub Desktop.
creating docker image behind proxy on Ubuntu

Sources

Install

Per https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

DNS

cat << EOF > /etc/docker/daemon.json
{
    "dns": ["10.0.0.2", "8.8.8.8"]
}
EOF

sudo service docker restart

Proxy

cat <<EOF | sudo tee -a /etc/default/docker
export http_proxy="http://myproxy.example.com:8080"
export https_proxy="https://myproxy.example.com:8080"
export no_proxy=<REGISTRY_IP>
EOF

# newly
mkdir -p /etc/systemd/system/docker.service.d
cat << EOF | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://www-proxy.example.com:80/"
EOF

sudo service docker restart

Build

sudo docker build -t foo/bar \
            --build-arg http_proxy="http://myproxy.example.com:8080" \
            --build-arg https_proxy="https://myproxy.example.com:8080" \
            .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment