Getting Docker for mac proxy variables through terminal

二次信任 提交于 2019-12-07 02:50:16

问题


I am using Docker for mac behind a proxy. I set up the proxy configuration in the Docker GUI under "Proxies" -> "Manual proxy configuration". This lets me download Docker images from the repository behind the proxy.

Next, I set the http_proxy and https_proxy environment variables and I use them in my docker-compose.yml to pass them to the build:

services:
  app:
    build:
      context: .
      args:
        http_proxy: $http_proxy
        https_proxy: $https_proxy

How can I get the variables that I set through the Docker GUI in the terminal so I don't have to set them twice? Are there any Docker-specific environment variables that I can use?


回答1:


If I understood correctly want you want, then you just need to read what's given by docker info:

❯ docker info | grep Proxy
Http Proxy: http://localhost:3128
Https Proxy: http://localhost:3128

If these two are set in the GUI, they will appear near the end of the output. If they are not set, they won't, and in my case, No Proxy: *.local, 169.254/16 will appear instead.




回答2:


Install proxycap or redsocks and relieve yourself from the annoying proxy errors for all your tools and not just Docker. Proxycap/Redsocks transparently redirect traffic to the specified proxy that you have, so you don't configure any proxy settings anymore.

Update: There is a docker image for redsocks in case you cannot install it on the host machine. https://hub.docker.com/r/ncarlier/redsocks/




回答3:


Best of my knowledge : it is not possible.

The only idea I get is to use sort of iptable rules (I guess there is similar stuff in mac) that redirect external ip packet to the proxy. It means your docker is clean, you simply activate / deactivate rules if you are behind a proxy or not.

It is not easy, but it is do-able.




回答4:


Either export them or you can use the right hand side in your script.

export http_proxy=$(docker info | grep 'Http Proxy' | cut -f2 -d:)
export https_proxy=$(docker info | grep 'Https Proxy' | cut -f2 -d:)


来源:https://stackoverflow.com/questions/45340644/getting-docker-for-mac-proxy-variables-through-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!