Pip can't use proxy from inside plugins/docker image

pip can’t use a proxy from inside the plugins/docker image

I get this for plugins/docker

119  Step 5/8 : RUN pip install flask 31s
120  ---> Running in 322792bd6c25 31s
121  Collecting flask                          32s
122  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f36182b5d68>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))': /simple/flask/

But pip is able to use the same proxy without issues in other images.
For example, the “python” image:

 1  + pip install -r requirements.txt                                                                                                       0s
 2  Collecting Flask==0.10.1 (from -r requirements.txt (line 1))                                                           0s
 3  Downloading Flask-0.10.1.tar.gz (544kB)                                                                                      1s
 4  Collecting Werkzeug>=0.7 (from Flask==0.10.1->-r requirements.txt (line 1))                              1s
 5  Downloading Werkzeug-0.13-py2.py3-none-any.whl (311kB)                                                        1s
 6  Collecting Jinja2>=2.4 (from Flask==0.10.1->-r requirements.txt (line 1))                                     1s
 7  Downloading Jinja2-2.10-py2.py3-none-any.whl (126kB)                                                              1s
 8  Collecting itsdangerous>=0.21 (from Flask==0.10.1->-r requirements.txt (line 1))                        2s
 9  Downloading itsdangerous-0.24.tar.gz (46kB)                                                                               2s
10  Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->Flask==0.10.1->-r requirements.txt (line 1))  2s
11  Downloading MarkupSafe-1.0.tar.gz                                                                                              2s
12  Building wheels for collected packages: Flask, itsdangerous, MarkupSafe                                   2s
13  Running setup.py bdist_wheel for Flask: started                                                                           2s
14  Running setup.py bdist_wheel for Flask: finished with status 'done'                                             3s
15  Stored in directory: /root/.cache/pip/wheels/b6/09/65/5fcf16f74f334a215447c26769e291c41883862fe0dc7c1430              3s
16  Running setup.py bdist_wheel for itsdangerous: started                                                               3s
17  Running setup.py bdist_wheel for itsdangerous: finished with status 'done'                                 3s
18  Stored in directory: /root/.cache/pip/wheels/fc/a8/66/24d655233c757e178d45dea2de22a04c6d92766abfb741129a           3s
19  Running setup.py bdist_wheel for MarkupSafe: started                                                                3s
20  Running setup.py bdist_wheel for MarkupSafe: finished with status 'done'                                   4s
21  Stored in directory: /root/.cache/pip/wheels/88/a7/30/e39a54a87bcbe25308fa3ca64e8ddc75d9b3e5afa21ee32d57           4s
22  Successfully built Flask itsdangerous MarkupSafe                                                                        4s
23  Installing collected packages: Werkzeug, MarkupSafe, Jinja2, itsdangerous, Flask                      4s
24  Successfully installed Flask-0.10.1 Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.13 itsdangerous-0.24

The docker plugin runs docker-in-docker. Perhaps some special configuration is required when working with proxy servers, such as setting the http_proxy, https_proxy and no_proxy variables? Or perhaps it is an issue with DNS [1] and you need to explicitly pass the dns server to the plugin using the custom_dns plugin parameter.

[1] https://github.com/moby/moby/issues/20037