title: How to set proxy in docker-in-docker (dind) in gitlab CI
body: <p>I am trying to set up a job with gitlab CI to build a docker image from a dockerfile, but I am behind a proxy.</p>
  
  <p>My <code>.gitlab-ci.yml</code> is as follows:</p>
  
  <pre><code>image: docker:stable
  
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    HTTP_PROXY: $http_proxy
    HTTPS_PROXY: $http_proxy
    http_proxy: $http_proxy
    https_proxy: $http_proxy
  
  services:
    - docker:dind
  
  before_script:
    - wget -O - www.google.com # just to test
    - docker search node # just to test
    - docker info # just to test
  
  build:
    stage: build
    script:
      - docker build -t my-docker-image .
  </code></pre>
  
  <p><code>wget</code> works, meaning that proxy setup is correct, in theory</p>
  
  <p>But the commands <code>docker search</code>, <code>docker info</code> and <code>docker build</code> do not work, apparently because of a proxy issue.</p>
  
  <p>An excerpt from the job output:</p>
  
  <pre><code>$ docker search node
  Warning: failed to get default registry endpoint from daemon (Error response from  daemon:
      [and here comes a huge raw HTML output including the following message: "504 - server did not respond to proxy"]
  </code></pre>
  
  <p>It appears docker does not read from the environment variables to setup proxy.</p>
  
  <p>Note: I am indeed using a runner in --privileged mode, <a href="https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor" rel="nofollow noreferrer">as the documentation instructs to do</a>.</p>
  
  <p>How do I fix this?</p>