3

I make container for nodejs project. Inside the project I am using private repository. I need an access to it. For that I am using next Dockerfile

FROM node:15

RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
COPY keys/ssh_config /root/.ssh/config
COPY keys/bitbucket /root/.ssh/bitbucket
RUN chmod 600 /root/.ssh/bitbucket

RUN npm install -g typescript ts-node
WORKDIR /var/www
EXPOSE 3000

ssh_config file is

Host bitbucket.org
     IdentityFile /root/.ssh/bitbucket
     StrictHostKeyChecking no

in my package.json I added next line

"my-interfaces": "git+ssh://bitbucket.org:MY_USER_NAME/my-interfaces.git#master",

After building container using docker-compose, I login inside container and run npm i but in the end I see next error

npm ERR! code 128
npm ERR! command failed
npm ERR! command git ls-remote ssh://git@bitbucket.org/MY_USER_NAME/my-interfaces.git
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-04-30T08_19_38_999Z-debug.log

I tried another way, I generate SSH key inside container and added public key to bitbucket, but I see the same error message. It reproduced on Ubuntu Linux, but same config is working on MacOS.

UPDATE I can make clone this repository from git by command git clone ...

Eugene
  • 157
  • 8
  • This is a very common `npm` problem, across all platforms and environments. You can try adding a command `ssh-add ~/.ssh/id_rsa` before running `npm install`, where `~/.ssh/id_rsa` is the filename of your private key. – Xeos May 09 '21 at 01:37
  • I tried that, in the docker I have to run `eval "ssh-agent"`, then `ssh-add ~/.ssh/id_rsa`. But it didn't help. I can make clone this repository, but I can't use `npm install` – Eugene May 14 '21 at 16:40

0 Answers0