2

I have a Docker container which is bringing up a project which has dependencies in a private repo.

Dockerfile is copying my passwordless SSH keys (permissions are 600 & 644):

COPY docker/config/id_rsa /root/.ssh/
COPY docker/config/id_rsa.pub /root/.ssh/

After copying, Composer dependencies are getting installed:

RUN echo *** >> /etc/hosts \
  && composer config -a -g *URL *USER *PASS \
  && composer install --prefer-dist --no-progress

At the same time I have deleted composer.lock to make sure nothing is left from previous installs.

Repositories part from composer looks like this:

"repositories": [
    {
        "type": "vcs",
        "url": "git@***:***/libs/***.git",
        "options": {
            "ssl": {
                "local_cert": "~/.ssh/id_rsa.pub"
            }
        }
    },
],

And during the creation of container I am getting an error saying:

[RuntimeException]
Failed to execute git clone --mirror 'git@***:***/libs/***.git' '/root/.composer/cache/vcs/.../'
Cloning into bare repository '/root/.composer/cache/vcs/...'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

Repository does indeed exist, SSH keys are valid, and strangest of all...if I omit the composer install command and enter the created container, change nothing and do it manually from terminal, it installs everything.

EDIT:

I have also tried manually in the RUN command writing the keys if by any case they weren't available during the container creation, but that didn't help.

I have also tried removing "options" section from Composer

3
  • How is the id_rsa.pem generated? You copy only the id_rsa and id_rsa.pub Commented Jul 18, 2019 at 8:05
  • Sorry, it is supposed to be id_rsa.pub. It is generated with ssh keygen. Both are copied Commented Jul 18, 2019 at 10:26
  • stackoverflow.com/… Commented Jul 18, 2019 at 12:35

1 Answer 1

0

What was missing were these parts in the RUN command:

echo "xxx.xxx.xxx.xxx my_server_name" >> /etc/hosts

ssh-keyscan -t rsa my_server_name >> ~/.ssh/known_hosts 

Once that was done I could omit "options" section completely from Composer

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.