Cloning a private repo with Composer in Docker (at runtime)

  composer-php, docker, git, ssh-agent

I am trying to install PHP packages using Composer, via the Composer Docker image. Some of those packages are in private git repos, so authentication is needed.

The SSH agent approach listed in the Docker image docs is not working for unknown reasons.

eval $(ssh-agent); docker run --rm --interactive --tty 
    --volume $PWD:/app --user $(id -u):$(id -g) 
    --volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp 
    --volume $SSH_AUTH_SOCK:/ssh-auth.sock --env SSH_AUTH_SOCK=/ssh-auth.sock 
    composer install --optimize-autoloader

The error I get is

Cloning failed using an ssh key for authentication, enter your GitHub
credentials to access private repos Head to
https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+fe2cdd1a88f1+2021-05-04+1339
to retrieve a token. It will be stored in "/tmp/auth.json" for future
use by Composer.

The applicable private key has been added to ssh-agent on my host, and I can clone the private repos there without any issues.

I’ve looked through many similar questions but did not find anything that leads to the repo being cloned.

Source: Docker Questions

LEAVE A COMMENT