Error with bootBuildImage on a GitLab CI

Hi,
I’m a DevOps team member and I need to create a GitLab CI that when created a tag, builds the related Docker image and loads it on the repository.

Unfortunately, I have encountered this issue and I have really no idea how to fix it.
For context, this is my .gitlab-ci.yml file:

image: docker.nexus.consorziometis.it/ci-cd/jmix2-jdk21:latest

variables:
  SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
  GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task

stages:
  - build-sonar
  - build-docker


build-sonar:
  stage: build-sonar

  cache:
    policy: pull-push
    key: "sonar-cache-$CI_COMMIT_REF_SLUG"
    paths:
      - "${SONAR_USER_HOME}/cache"
      - sonar-scanner/

  script: gradle build sonar
  allow_failure: true
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: $CI_COMMIT_BRANCH == 'master'
    - if: $CI_COMMIT_BRANCH == 'main'

build-container:
  stage: build-docker
  services:
    - docker:dind
  variables:
    DOCKER_HOST: tcp://docker:2375/
  script:
    - GRADLE_OPTS="-Xms1g -Xmx4g" gradle -Pvaadin.productionMode=true bootBuildImage --no-build-cache
    - docker login --username $NEXUS_USER --password $NEXUS_PASS
  rules:
    - if: $CI_COMMIT_TAG

(the script part is not complete cos I have encountered the issue at the first command)

When the build heads to the final part, I get this error:

Execution failed for task ':bootBuildImage'.
> Connection to the Docker daemon at 'tcp://docker:2375/' failed with error "No such file or directory"; ensure the Docker daemon is running and accessible

Which to makes no sense cos the docker:dind service is there, all the possible needed variables are set.

I will also put the Dockerfile content here in case it’s needed:

FROM docker:latest

# Install dependencies
RUN apk add --no-cache bash curl unzip openjdk21 nodejs npm

# Set Gradle version (for future clarity only)
ENV GRADLE_VERSION=8.12.1
ENV GRADLE_HOME=/usr/local/gradle/gradle-8.12.1
ENV PATH="${GRADLE_HOME}/bin:${PATH}"

# Install Gradle (don't rely on ENV vars in RUN for versioned paths)
RUN mkdir -p /usr/local/gradle && \
    curl -fSL -o /tmp/gradle.zip https://services.gradle.org/distributions/gradle-8.12.1-bin.zip && \
    unzip /tmp/gradle.zip -d /usr/local/gradle && \
    ln -s /usr/local/gradle/gradle-8.12.1/bin/gradle /usr/bin/gradle && \
    rm /tmp/gradle.zip

# Test Gradle
RUN gradle --version

Does someone have any clue of what i’m doing wrong?
Thank you in advance!

file/directory permission issue?