Different behavior when running dind and using the custom image directly in stage

Hello all,

for one project we have, we run a few audit stages inside of a previously build docker image. The image gets build as a first step (stage) in our CI run and the remaining steps are executing the different audit checks.

In order to reduce execution time, I thought it would make sense to use the image built in step 1 as image in the subsequent steps. But for some reason this yields a different result than using docker as image with the dind service. Please see the example below, where I’d like to understand the difference of myworkingstage and myfailingstage.

stages:
  - build
  - myworkingstage
  - myfailingstage

build:
  image: docker
  stage: build
  services:
    - docker:20.10.22-dind
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker build -t $CI_REGISTRY_IMAGE:ci-$CI_COMMIT_SHORT_SHA .
    - docker push $CI_REGISTRY_IMAGE:ci-$CI_COMMIT_SHORT_SHA

myworkingstage:
  image: docker
  stage: myworkingstage
  services:
    - docker:20.10.22-dind
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker run --rm $CI_REGISTRY_IMAGE:ci-$CI_COMMIT_SHORT_SHA mycheck

myworkingstage:
  image: $CI_REGISTRY_IMAGE:ci-$CI_COMMIT_SHORT_SHA
  stage: myfailingstage
  script:
    - mycheck

I appreciate any input, thank you for helping with understanding this.

Cheers,

Chris