Configure Docker to use a proxy with or without authentication
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux Atomic Host
- Red Hat OpenStack Platform 13.0 (RHOSP)
- Docker
Issue
- How can docker be configured to route through an HTTP proxy that requires authentication?
- How can docker be configured to route through an HTTP proxy?
Resolution
You have 2 methods:
Method 1: Configuring proxy variables via /etc/sysconfig/docker file
- With authentication
HTTP_PROXY=http://USERNAME:PASSWORD@10.0.1.1:8080/
HTTPS_PROXY=http://USERNAME:PASSWORD@10.0.0.1:8080/
NO_PROXY= hostname.example.com,172.30.123.45
- Without authentication
HTTP_PROXY=http://10.0.1.1:8080/
HTTPS_PROXY=http://10.0.0.1:8080/
NO_PROXY=hostname.example.com,172.30.123.45
Method 2: Adding environment variables for Docker
1: Create a drop-in
# mkdir /etc/systemd/system/docker.service.d
2: Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:
- With authentication
[Service]
Environment="HTTP_PROXY=http://USERNAME:PASSWORD@10.0.1.1:8080/"
Environment="HTTPS_PROXY=http://USERNAME:PASSWORD@10.0.0.1:8080/"
Environment="NO_PROXY= hostname.example.com,172.30.123.45"
- Without authentication
[Service]
Environment="HTTP_PROXY=http://10.0.1.1:8080/"
Environment="HTTPS_PROXY=http://10.0.0.1:8080/"
Environment="NO_PROXY= hostname.example.com,172.30.123.45"
3: reload the systemd daemon
# systemctl daemon-reload
4: restart docker
# systemctl restart docker
5: Verify that the configuration has been loaded:
$ sudo systemctl show docker --property Environment
Environment=GOTRACEBACK=crash HTTP_PROXY=http://10.0.0.1:8080/ HTTPS_PROXY=http://10.0.0.1:8080/ NO_PROXY=hostname.example.com,172.30.123.45
SBR
Components
Category
Tags
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.