I’m attempting to run a CI/CD pipeline using GitLab CI with Kubernetes runners. I’m using a docker:dind
base image to build and deploy my Java application with Maven. Here is the Dockerfile I am using:
FROM docker:dind
RUN apk update && apk add --no-cache openjdk21 maven git
ENV MAVEN_HOME=/usr/share/java/maven-3.9.8
ENV PATH=$MAVEN_HOME/bin:$PATH
CMD ["dockerd-entrypoint.sh"]
However, when I run the pipeline, I encounter the following log error:
Could not find a valid Docker environment.
I am using Kubernetes runners to execute my CI/CD jobs, and it seems like my configuration is unable to find or start a Docker environment correctly.
I tried using different dind versions, but i think the problem is related to the Kubernetes runners, because the docker wont be in one single machine (as it was before)
2
Answers
I think. It is because Docker is not more a part of kubernetes installation. Just google about it. For example. https://kodekloud.com/blog/kubernetes-removed-docker-what-happens-now/
Most likely you have another CRI containerD. Just take another base image. some alphine or ubuntu.
Did you tried this below approach
In your GitLab CI configuration, you need to enable DinD explicitly. Add the DOCKER_TLS_CERTDIR environment variable and set the services configuration in your .gitlab-ci.yml file to use the docker:dind image.
example: .gitlab-ci.yml configuration:
Since DinD needs privileged mode to run ensure your Kubernetes runner configuration allows privileged containers. This is typically set in your config.toml on the GitLab Runner side:
In some cases Kubernetes DNS or networking issues can prevent the docker service from being accessible. To address this use the following in your .gitlab-ci.yml:
If DinD continues to cause issues an alternative approach is to use Docker socket binding which allows Docker commands to run on the host machine Docker daemon without requiring a separate Docker service. In this approach map the Docker socket from the host to your container: