Skip to content

Instantly share code, notes, and snippets.

@vladak
Last active March 3, 2022 09:54
Show Gist options
  • Save vladak/0ebad88f83c4e84906e11f9c82632ceb to your computer and use it in GitHub Desktop.
Save vladak/0ebad88f83c4e84906e11f9c82632ceb to your computer and use it in GitHub Desktop.

Docker behind proxy

https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy

mkdir /etc/systemd/system/docker.service.d
cat << EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="HTTPS_PROXY=http://proxy.example.com:80/"
Environment="NO_PROXY=localhost,127.0.0.1,::1"
EOF

sudo systemctl daemon-reload
sudo systemctl show --property Environment docker
sudo systemctl restart docker

Docker without sudo

from https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo

usermod -aG docker $USER

and relogin or run newgrp docker

Note: adding user to the docker group basically gives them root privileges.

Docker build with proxy

per https://stackoverflow.com/questions/46444026/use-proxy-inside-a-docker-container

run the command with environment:

FROM ubuntu

RUN export "http_proxy=http://host:port" \
    && export "https_proxy=http://host:port" \
    && apt-get update \
    && apt-get install -y SOME-PACKAGE

or add the environment to the whole Dockerfile:

FROM ubuntu

ENV http_proxy http://host:port
ENV https_proxy http://host:port

RUN apt-get update \
    && apt-get install -y SOME-PACKAGE

This will work for apt-get. Things like Maven have their own environment variables:

ENV MAVEN_OPTS -Dhttp.proxyHost=www-proxy-lon.uk.oracle.com -Dhttp.proxyPort=80 -Dhttps.proxyHost=www-proxy-lon.uk.oracle.com -Dhttps.proxyPort=80

NOTE: these ENV entries have to be repeated after each FROM in given Dockerfile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment