2

I'm using Mac and Docker for my local PHP/Nginx environment.

I decided to add my own private repository to composer.json. It looks something like this:

"repositories":[
        {
            "type": "vcs",
            "url": "ssh://git@privaterepo.com/my-repo/php-code-fixer.git"
        }
    ]

I tried to execute following command: docker exec -it mysite_php_1 php /usr/local/bin/composer.phar require --dev my-repo/php-code-fixer

I get this error:

 [RuntimeException]                                                                                       
  Failed to execute git clone --mirror 'ssh://git@privaterepo.com/my-repo/php-code-fixer.git'  
   '/root/.composer/cache/vcs/ssh---ssh://git@privaterepo.com/my-repo/php-code-fixer.git/'           
                                                                                                           
  Cloning into bare repository '/root/.composer/cache/vcs/ssh---ssh://git@privaterepo.com/my-repo/php-code-fixer.git'...                                                                                    
  git@privaterepo.com: Permission denied (public key).                                              
  fatal: Could not read from remote repository.                                                            
                                                                                                           
  Please make sure you have the correct access rights                                                      
  and the repository exists.  

I tried to clone the repo via ssh without docker and it works. I have permission.

I tried to solve above problem by mounting my .ssh folder to docker container like this:

  php:
    volumes:
      - ~/.ssh:/root/.ssh

but then I get

[RuntimeException]                                                                                       
  Failed to execute git clone --mirror 'ssh://git@privaterepo.com/my-repo/php-code-fixer.git'  
   '/root/.composer/cache/vcs/ssh---ssh://git@privaterepo.com/my-repo/php-code-fixer.git/'           
                                                                                                           
  Cloning into bare repository '/root/.composer/cache/vcs/ssh---my ssh repo'...                                                                                    
  /root/.ssh/config: line 8: Bad configuration option: usekeychain                                         
  /root/.ssh/config: terminating, 1 bad configuration options                                              
  fatal: Could not read from remote repository.                                                            
                                                                                                           
  Please make sure you have the correct access rights                                                      
  and the repository exists. 

How do I install my private repository using Composer from Docker? I cannot execute composer outside of docker because my machine doesn't have Memcached installed (the docker environment does) and because of that I'm getting Class 'Memcached' not found. I could install Memcached but then everyone who wants to use my script needs to have Memcached installed.

Richard Barber
  • 5,257
  • 2
  • 15
  • 26
FosAvance
  • 2,363
  • 9
  • 36
  • 52
  • Does this answer your question? [.ssh/config: "Bad configuration option: UseKeychain" on Mac OS Sierra 10.12.6](https://stackoverflow.com/questions/47455300/ssh-config-bad-configuration-option-usekeychain-on-mac-os-sierra-10-12-6) – β.εηοιτ.βε Mar 09 '21 at 21:41
  • Seems to be [a version issue with Open SSH](http://webpatrika.blogspot.com/2019/03/sshconfig-bad-configuration-option.html) which your alpine image is using which your Mac isn't (mapped volume) – Jaquarh Mar 09 '21 at 21:43
  • This might help. I'll try it out. Is it even safe to mount .ssh to. docker container? – FosAvance Mar 09 '21 at 22:06
  • It is not good practice because it relies on the host machine to have prerequisites installed which containerisation avoids. Instead, you should build a DockerFile that mounts your SSH configuration into an image for your Container to run. – Jaquarh Mar 10 '21 at 07:56
  • Isn't that what I had in mind, mounting .ssh folder in container? – FosAvance Mar 10 '21 at 08:15
  • Sorry, I mean copy. So the image contains the SSH configuration you can then distribute via a repository and integrate in your docker-compose.yml. If you mount it from the node directory, you then need to distribute that directory to others or assume they have the correct SSH configuration on their own nodes. Neither are unsafe, just mounting here would be bad practice - not unachievable however. – Jaquarh Mar 10 '21 at 16:34

0 Answers0