Docker & Ubuntu Proxy
Setting Up a System-Wide Proxy on Ubuntu
To configure proxy settings that apply to all users, shells and services on an Ubuntu host, add environment variables in one of the following locations.
1. Edit /etc/environment
/etc/environment
Open the file with root privileges:
sudo nano /etc/environment
Add the proxy definitions (customize host, port and no-proxy list as required):
http_proxy="http://myproxy.server.com:8080/" https_proxy="http://myproxy.server.com:8080/" ftp_proxy="http://myproxy.server.com:8080/" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" # Upper-case variants for compatibility with certain applications HTTP_PROXY="http://myproxy.server.com:8080/" HTTPS_PROXY="http://myproxy.server.com:8080/" FTP_PROXY="http://myproxy.server.com:8080/" NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
Save and exit (in nano: Ctrl+O, Enter, Ctrl+X).
Apply changes immediately by running:
source /etc/environment
Otherwise, the settings will take effect at the next login.
2. Create a Shell Profile Script
An alternative approach uses /etc/profile.d/
to export variables for all interactive and non-interactive shells.
Create the script file:
sudo nano /etc/profile.d/proxy.sh
Insert the following content:
#!/bin/sh export http_proxy="http://myproxy.server.com:8080/" export https_proxy="http://myproxy.server.com:8080/" export ftp_proxy="http://myproxy.server.com:8080/" export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
Make the script executable:
sudo chmod +x /etc/profile.d/proxy.sh
Reload the profile or log in again:
source /etc/profile.d/proxy.sh
3. Configure APT to Use the Proxy
To ensure that apt-get
and related tools honor the proxy:
Open or create an APT configuration snippet:
sudo nano /etc/apt/apt.conf.d/95proxies
Add the following lines:
Acquire::http::proxy "http://myproxy.server.com:8080/"; Acquire::https::proxy "http://myproxy.server.com:8080/"; Acquire::ftp::proxy "ftp://myproxy.server.com:8080/";
Save, exit and test with:
sudo apt-get update
Setting Up a Proxy for Docker
Docker’s daemon and build processes require their own proxy configuration when managed by systemd.
Create the systemd drop-in directory if it does not already exist:
sudo mkdir -p /etc/systemd/system/docker.service.d
Create or edit the proxy configuration file:
sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf
Add the following content, adapting values as needed:
[Service] Environment="HTTP_PROXY=http://myproxy.server.com:8080/" Environment="HTTPS_PROXY=http://myproxy.server.com:8080/" Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example,.corp"
Reload systemd and restart Docker to apply the new settings:
sudo systemctl daemon-reload sudo systemctl restart docker
Verify that the environment variables are active:
sudo systemctl show --property=Environment docker
Last updated