Search code examples
dockerproxygitlabgitlab-cidocker-in-docker

How to set proxy in docker-in-docker (dind) in gitlab CI


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.

My .gitlab-ci.yml is as follows:

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 .

wget works, meaning that proxy setup is correct, in theory

But the commands docker search, docker info and docker build do not work, apparently because of a proxy issue.

An excerpt from the job output:

$ 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"]

It appears docker does not read from the environment variables to setup proxy.

Note: I am indeed using a runner in --privileged mode, as the documentation instructs to do.

How do I fix this?


Solution

  • Oddly, the solution was to use a special dind (docker-in-docker) image provided by gitlab instead, and it works without setting up services and anything. The .gitlab-ci.yml that worked was as follows:

    image: gitlab/dind:latest
    
    before_script:
      - wget -O - www.google.com
      - docker search node
      - docker info
    
    build:
      stage: build
      script:
        - docker build -t my-docker-image .
    

    Don't forget that the gitlab-runner must be registered with the --privileged flag.