Gitlab ci : docker image in private and stage required theses images - impossible tu use before_script

Hello,
I use already gitlab ci on several opensource project, but now I try to use it in my work.

The problematic is that some jobs require to run inside a specific docker image. So my first idea was this :

image: docker:latest

services:
  - docker:dind

stages:
  - build
  - test

variables:
  DOCKER_HOST: tcp://docker:2376
  DOCKER_TLS_CERTDIR: "/certs"
  DOCKER_DRIVER: overlay2

before_script:
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

build:assets:
  stage: build
  image: node:12
  script:
    - npm ci
    - npm run build

build:php:
  stage: build
  image: registry.gitlab.com/XX/YYY/php-cli:7.4
  script:
    - composer install -o --ansi --no-progress

test:phpunit:
  stage: test
  image: registry.gitlab.com/XX/YYY/php-cli:7.4
  script:
    - vendor/bin/phpunit

I try several variation around this but globally I need to do this

  • use some image from our docker image repository
  • run some command in theses docker

But I’m struggle with

  • docker executable not found
  • or docker login issue
  • or some other random issue

If I run the docker login in normal job step like

init:
  stage: init
  image: docker:latest
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

No problem of login but it failed later because it’s not logged in

Authenticating with credentials from job payload (GitLab Registry) [: 1: [: Syntax error: end of file unexpected (expecting "then")

If I use the before_script when I’m at the node step, it fails because it he didn’t found the docker executable

So I probably miss something but i don’t see what…
thanks for the help

the only thing that seems working is using docker command to launch stuff but it’s not really helpfull

I finnaly drop it and create a private runner where the authentication is made on the host sid