Different behavior of two gitlab runners with same docker-compose config

For a PHP/Symfony project, I currently setup the Gitlab CI (self-hosted CE) for building the Docker images and running tests and code-style checks.

To run it parallel, I have one build job which is building the Docker image and two jobs, the first is running the phpunit tests, the other one runs the code style checks like phpstan and codesniffer.

The project has some composer dependencies which are installed with the command docker-compose run --entrypoint="composer install -n" php. The project folder is a volume configured in the docker-compose.yml file:


  php:
    image: 'git.cd.de:5050/sf/sf-software:dev_latest'
    depends_on:
      - database
    environment:
      TIMEZONE: Europe/Berlin
      XDEBUG_MODE: 'off'
      XDEBUG_CONFIG: >-
        client_host=host.docker.internal
        client_port=9003
        idekey=PHPSTORM
      PHP_IDE_CONFIG: serverName=sf
    volumes:
      - './:/var/www/html'
      - './docker/php/php.ini:/usr/local/etc/php/php.ini:ro'

This is working on my local machine and also in the CI, it’s working - but only, if it’s running on “the one” gitlab runner, which is installed on a second virtual machine, while the “second runner” is installed on the same machine on which is also gitlab running. The runner “second runner” fails with the following message:

    $ docker-compose run --entrypoint="composer install -n" php
    Creating cd-software_php_run ... 
    Creating cd-software_php_run ... done
    Composer could not find a composer.json file in /var/www/html
    To initialize a project, please create a composer.json file. See https://getcomposer.org/basic-usage

The composer.json file does not exists in the docker image php.

It makes no difference in the result whether the “second runner” performs the test-job or the check-job. The “second job” always fails with that error.

My .gitlab-ci.yml file:

    variables:
      DOCKER_DRIVER: overlay
    
    before_script:
      - apk add --no-cache docker-compose
      - docker info
      - docker-compose --version
    
    build_dev:
      services:
        - docker:dind
      script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker pull $CI_REGISTRY_IMAGE:dev_latest || true
        - docker build --cache-from $CI_REGISTRY_IMAGE:dev_latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:dev_latest .
        - docker push $CI_REGISTRY_IMAGE:dev_latest
    
    tests:
      services:
        - docker:dind
      needs:
        - build_dev
      script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker-compose pull
        - docker-compose run --entrypoint="composer install -n" php
        - docker-compose run --entrypoint="bin/console doctrine:migrations:migrate -n" php
        - docker-compose run --entrypoint="bin/console doctrine:schema:validate" php
        - docker-compose run --entrypoint="bin/console doctrine:fixtures:load -n" php
        - docker-compose run --entrypoint="vendor/bin/simple-phpunit -c phpunit.xml.dist" php
    
    checks:
      services:
        - docker:dind
      needs:
        - build_dev
      script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker-compose pull
        - ls -la
        - docker-compose run --entrypoint="ls -la" php
        - docker-compose run --entrypoint="composer install -n" php
        - docker-compose run --entrypoint="composer run check-style" php
        - docker-compose run --entrypoint="composer run phpstan" php