Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 928
Pedro A Avatar asked Oct 20 '25 14:10

Pedro A


1 Answers

If you want to be able to use docker-in-docker (dind) in gitlab CI behind proxy, you will also need to setup no_proxy variable in your gitlab-ci.yml file. NO_PROXY for host "docker".

This is the gitlab-ci.yml that works with my dind:

image: docker:19.03.12

variables:
  DOCKER_TLS_CERTDIR: "/certs"
  HTTPS_PROXY: "http://my_proxy:3128"
  HTTP_PROXY: "http://my_proxy:3128"
  NO_PROXY: "docker"

services:
  - docker:19.03.12-dind
  
before_script:
  - docker info

build:
  stage: build
  script:
    - docker run  hello-world

Good luck!

like image 140
Robert Avatar answered Oct 23 '25 03:10

Robert