elclanrs
elclanrs

Reputation: 94131

Getting Docker for mac proxy variables through terminal

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?

Upvotes: 7

Views: 1320

Answers (4)

yamenk
yamenk

Reputation: 51876

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/

Upvotes: 3

BottleD JinnI
BottleD JinnI

Reputation: 56

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:)

Upvotes: 0

Metaphox
Metaphox

Reputation: 2106

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.

Upvotes: 1

wargre
wargre

Reputation: 4753

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.

Upvotes: 0

Related Questions