How do I log into a Gitlab CI container?

  composer-php, docker, gitlab, gitlab-ci, php

I need to install via composer a private package from the corporate namespace in Gitlab CI.

Dependency in composer.json.

    "repositories": [
            "type": "git",
            "url": "[email protected]:namespace/package.git"
    "require": {
        "namespace/package": "dev-master",



    - deploy

.setup_ssh: &setup_ssh
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client zip unzip -y )'
    - eval $(ssh-agent -s)
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_PUBLIC_KEY" > ~/.ssh/
    - echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa
    - ssh-keyscan >> ~/.ssh/known_hosts
    - ssh-keyscan $DEV_HOST >> ~/.ssh/known_hosts
    - chmod 600 ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/
    - chmod 644 ~/.ssh/known_hosts
    - ssh-add ~/.ssh/id_rsa

.setup_composer: &setup_composer
    - composer i -n

deploy to dev:
    stage: deploy
        - *setup_ssh
        - *setup_composer

Installing composer i -n crashes on a private package.

Cloning into bare repository ‘/root/.composer/cache/vcs/’…
remote: ========================================================================
remote: The project you were looking for could not be found or you don’t have permission to view it.
remote: ========================================================================
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I tried running the container locally and installing the composer dependencies inside the container interactively.

– Syncing namespace/package (dev-master fa27046) into cache
Cloning failed, enter your GitLab credentials to access private repos
A token will be created and stored in “/root/.composer/auth.json”, your password will never be stored
To revoke access to this token you can visit

I have 2FA configured. For the test, I created a token and tried to log in.

composer config --global [token]

After that, everything worked. But the problem is that this is my personal token.

How do I log into a Gitlab CI container?

Source: Docker Questions