I am trying to build a docker image as part of a gitlab ci job. I work on my own gitlab instance with a separate machine running ci jobs. I have tried and failed with many different configurations for using Docker in Docker. My current try is the method from this blog post: https://medium.com/@tonywooster/docker-in-docker-in-gitlab-runners-220caeb708ca
When executing a CI job on this runner with the docker command I get the following error:
ERROR: Failed to remove network for build
ERROR: Preparation failed: Cannot connect to the Docker daemon at tcp://gitlab-dind:2375. Is the docker daemon running? (docker.go:745:240s)
Why is that and how can I fix it? I am also happy with any other working method to build and push a docker container in my CI job. I am happy to provide any further information, but I am not sure what would help and don’t want to bloat the post.
As requested my gitlab CI file looks like this:
image: docker
stages:
- package
- test
- push
build docker image:
stage: package
tags:
- docker
script:
- cat /proc/self/cgroup
- docker info
- docker build -t $CI_REGISTRY_IMAGE .
test docker image:
stage: test
tags:
- docker
script:
- docker run $CI_REGISTRY_IMAGE python testscript.py
push docker image:
stage: push
tags:
- docker
script:
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker push $CI_REGISTRY_IMAGE