Paths and contexts in GitlabCI DIND service enabled job

Paths and contexts in GitlabCI DIND service enabled job

I run jobs with my DIND image, same as the original dind from docker but with some small tools on top like git. When I run a job I can see that if i run a non docker related command i can access the runner user paths such as $HOME/.something but when I run a docker based task access to such path is not possible. So here is my question.

Can someone explain what is the difference in paths that are used while a simple command is used vs when a docker context is provided?

Specific example in my .gitlab-ci

image: diegogullo/docker-image-extras

services:
  - docker:dind

before_script:
  - git config --global gitlab.accesstoken $GITLAB_PERSONAL_TOKEN
  - cp /root/.gitconfig ./.gitconfig
  - export UID && make up_ci

build:
  script:
    - export UID && make tests
  artifacts:
    paths:
      - reports/*
    expire_in: 1 year
    reports:
      junit: reports/junit.xml
  rules:
    - if: $CI_COMMIT_TAG
      when: never
    - when: always

after_script:
  - docker-compose logs
  - make PASS_CMD="ls -la" composer_run
  - make PASS_CMD="ls -la /home/composer" composer_run
  - make PASS_CMD="pwd" composer_run
  - ls -la $HOME
  - pwd
  - git config --list
  - echo "CI JOB STATUS- $CI_JOB_STATUS"
  - export UID && make down
  - make PASS_CMD="git config --list" composer_run

And my composer file i have this mount point with $HOME variable

  composer:
    build:
      context: docker/composer
    user: $UID
    volumes:
      - websrc:/app
      - ${COMPOSER_HOME}:/home/composer/.config/composer
      - ${COMPOSER_CACHE_DIR}:/home/composer/.cache/composer
      - ${HOME}/.gitconfig:/home/composer/.gitconfig:Z
    command: composer install
    working_dir: /app
    environment:
      - COMPOSER_HOME=/home/composer/.config/composer
      - HOME=/home/composer

This works on my machine as despite being outside the docker context it is mounted correctly from my PC home directory so i can always load the .gitconfig file.

On GitlabCI the $HOME dir is /root, and so if git config is available it is under /root/.gitconfig . However when the docker-compose step is run (make up in my gitlab config calls docker-compose) then docker does not see this path and I dont know what path it sees.

Can someone explain the difference on what is happening in a DIND enabled context on the GitlabCI runner when a docker step is run compared to a standard shell command?

I hope the above is clear but do ask if needed.