Gitlab-runner and docker behind a proxy

After reading many articles and trying many things, this is how I solved it.

For docker daemon itself to use a proxy, configure environment variables using systemd file /etc/systemd/system/docker.service.d/http-proxy.conf :

[Service]
Environment="HTTP_PROXY=http://user:pass@proxy.domain.com:3128/"
Environment="HTTPS_PROXY=http://user:pass@proxy.domain.com:3128/"
Environment="NO_PROXY=localhost,docker,*.domain.com"

For gitlab-runner daemon itself to use a proxy, configure environment variables using systemd file /etc/systemd/system/gitlab-runner.service.d/http-proxy.conf :

[Service]
Environment="HTTP_PROXY=http://user:pass@proxy.domain.com:3128/"
Environment="HTTPS_PROXY=http://user:pass@proxy.domain.com:3128/"
Environment="NO_PROXY=localhost,docker,*.domain.com"

Reload systemd and restart docker daemon:

systemctl daemon-reload
systemctl restart docker

For git commands run by gitlab-runner to use a proxy, use gitlab-runner config file. In /etc/gitlab-runner/config.toml , under [[runners]] , add the following line:

pre_clone_script = "git config --global http.proxy $HTTP_PROXY; git config --global https.proxy $HTTPS_PROXY"

For containers started by gitlab-runner to have proxy environment variables, use per-user docker config file. Add or edit /home/gitlab-runner/.docker/config.json :

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://user:pass@proxy.domain.com:3128",
     "httpsProxy": "http://user:pass@proxy.domain.com:3128",
     "noProxy": "localhost,docker,*.domain.com"
   }
 }
}

Restart gitlab-runner daemon:

systemctl restart gitlab-runner

You should be good to go at this point.

This entry was posted in Computer, Linux, Networking and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.