Reputation: 16291
I've had CI/CD set up in our private GitLab instance for a while now to build some packages, create docker images from them, and push them to our internal registry. The configuration looks like this:
stages:
- build
services:
- docker:18.09.4-dind
image: localregistry/utilities/tools:1.0.5
build:
stage: build
script:
- mvn install
- docker build -t localregistry/proj/image:$VERSION .
- docker push localregistry/proj/image:$VERSION
tags:
- docker
This has worked quite well up until today, when we started getting hit with rate limiting errors from Docker. We have a large company so this isn't entirely unexpected, but it prompted me to look at locally caching some of the docker images that we use frequently. As a quick test, I pulled, retagged, and pushed to our local registry the docker:18.09.4-dind
image and changed the line in the CI/CD configuration to:
services:
- localregistry/utilities/docker:18.09.4-dind
To my surprise when running the CI/CD job, while the image appeared to start up fine I started having docker problems:
$ docker build -t localregistry/proj/image:$VERSION .
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
The next hour or so was spent examining the runner and the various docker environments that get executed there, trying to figure out what the difference could be from simply retagging the DIND image, but couldn't figure anything out; the only difference that could be found is that DOCKER_HOST=tcp://docker:2375
was set in the environment when using docker:18.09.4-dind
, but not when using localregistry/utilities/docker:18.09.4-dind
- although setting it explicitly didn't help, triggering this message:
error during connect: Get http://docker:2375/v1.39/containers/json?all=1: dial tcp: lookup docker on 151.124.118.131:53: no such host
During that time the rate limit was lifted and I was able to switch back to the normally tagged version, but I can't see a reason why a locally tagged version wouldn't work; any ideas as to why this is?
Upvotes: 4
Views: 1651
Reputation: 2195
I guess your whole problem would be solved with using an alias
for your new docker dind image. Just replace the services
section with the following:
services:
- name: localregistry/utilities/docker:18.09.4-dind
alias: docker
This causes your docker daemon (dind) service to be accessible under the name docker
, which is the default hostname for docker daemon.
See also extended docker configuration options in GitLab CI for more details.
Upvotes: 5