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

  1. Open the file with root privileges:

    sudo nano /etc/environment
  2. 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"
  3. Save and exit (in nano: Ctrl+O, Enter, Ctrl+X).

  4. 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.

  1. Create the script file:

  2. Insert the following content:

  3. Make the script executable:

  4. Reload the profile or log in again:

3. Configure APT to Use the Proxy

To ensure that apt-get and related tools honor the proxy:

  1. Open or create an APT configuration snippet:

  2. Add the following lines:

  3. Save, exit and test with:


Setting Up a Proxy for Docker

Docker’s daemon and build processes require their own proxy configuration when managed by systemd.

  1. Create the systemd drop-in directory if it does not already exist:

  2. Create or edit the proxy configuration file:

  3. Add the following content, adapting values as needed:

  4. Reload systemd and restart Docker to apply the new settings:

  5. Verify that the environment variables are active:

Last updated