How to configure default environment to propagated to all containers?

Viewed 158

I have added the environment variables under the docker.service.d and reloaded , restarted the docker service on the machine but when i logged into the container, those environment variables are not propagated to containers (i was unable to view those env values). Can i please know if there any additional steps needed to be added.

Thanks

1 Answers

The correct way to configure default environment to propagate environment to containers is recorded in configure-the-docker-client:

  1. On the Docker client, create or edit the file ~/.docker/config.json in the home directory of the user that starts containers. Add JSON similar to the following example. Substitute the type of proxy with httpsProxy or ftpProxy if necessary, and substitute the address and port of the proxy server. You can also configure multiple proxy servers simultaneously.

    You can optionally exclude hosts or ranges from going through the proxy server by setting a noProxy key to one or more comma-separated IP addresses or hosts. Using the * character as a wildcard for hosts and using CIDR notation for IP addresses is supported as shown in this example:

    {
     "proxies":
     {
       "default":
       {
         "httpProxy": "http://192.168.1.12:3128",
         "httpsProxy": "http://192.168.1.12:3128",
         "noProxy": "*.test.example.com,.example2.com,127.0.0.0/8"
       }
     }
    }
    

    Save the file.

  2. When you create or start new containers, the environment variables are set automatically within the container.

Check the default environment after set config.json:

~$ docker run --rm -it ubuntu:16.04 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=6ca0f86604ea
TERM=xterm
HTTPS_PROXY=http://192.168.1.12:3128
https_proxy=http://192.168.1.12:3128
NO_PROXY=*.test.example.com,.example2.com,127.0.0.0/8
no_proxy=*.test.example.com,.example2.com,127.0.0.0/8
HTTP_PROXY=http://192.168.1.12:3128
http_proxy=http://192.168.1.12:3128
HOME=/root
Related