Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to authenticate on Dockerhub before pulling docker:dind with Gitlab CI runner

When I run this Gitlab CI job on my own runner “myrunner”

test:
  tags: 
    - myrunner
  image: docker:latest
  stage: build
  services:
    - docker:dind
  script:
    - echo "It works!"
  rules:
    - when: always

I get this error message:

Preparing the "docker" executor
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
ERROR: Preparation failed: Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit (docker.go:142:1s)
Will be retried in 3s ...

How can I authenticate before pulling the image docker:dind to avoid the pull rate limit on Dockerhub?

Steps to create own Gitlab runner:

Start runner:

docker run -d --name gitlab-runner --restart always \
     -v /srv/gitlab-runner/config:/etc/gitlab-runner \
     -v /var/run/docker.sock:/var/run/docker.sock \
     gitlab/gitlab-runner:latest

Register:

docker run --rm -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
  --non-interactive \
  --executor "docker" \
  --docker-image docker:stable \
  --url "DOMAIN" \
  --registration-token "REGISTRATION_TOKEN" \
  --description "docker-runner" \
  --tag-list "myrunner" \
  --run-untagged="true" \
  --locked="false" \
  --access-level="not_protected" \
  --docker-volumes "/certs/client" \
  --docker-volumes /var/run/docker.sock:/var/run/docker.sock \
  --docker-privileged
like image 855
Matthias Munz Avatar asked Nov 24 '20 08:11

Matthias Munz


People also ask

What is Docker DIND in GitLab?

gitlab/dind is image that should be used to build projects with docker-based workflow. The image runs Docker Engine and includes Docker Compose which allows to use full docker toolkit from build script. docker pull gitlab/dind. © 2022 Docker Inc.


1 Answers

I added this to my gitlab-ci.yml:

variables:
    DOCKER_AUTH_CONFIG: '{ "auths": { "https://index.docker.io/v1/": { "auth": "$DOCKER_AUTH" } }}'

The value of $DOCKER_AUTH can be generated with

echo -n "my_username:my_password" | base64

with the username/password for Dockerhub.

like image 136
Matthias Munz Avatar answered Nov 15 '22 05:11

Matthias Munz