Node installation with docker not working
Asked by Siriwudhi Sawaidee:

I tried to create a Dockerfile for my project. I also installed an external git repository using ssh. When building the project, this error occurred.

```
 > [builder 6/8] RUN --mount=type=ssh npm ci:
#13 81.97 npm notice 
#13 81.97 npm notice New minor version of npm available! 8.11.0 -> 8.15.0
#13 81.97 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.15.0>
#13 81.97 npm notice Run `npm install -g npm@8.15.0` to update!
#13 81.97 npm notice 
#13 81.97 npm ERR! code 128
#13 81.98 npm ERR! An unknown git error occurred
#13 81.98 npm ERR! command git --no-replace-objects ls-remote ssh://git@bitbucket.org/houseofdevtech/verscan-protobuf.git
#13 81.98 npm ERR! Warning: Permanently added 'bitbucket.org' (RSA) to the list of known hosts.
#13 81.98 npm ERR! git@bitbucket.org: Permission denied (publickey).
#13 81.98 npm ERR! fatal: Could not read from remote repository.
#13 81.98 npm ERR! 
#13 81.98 npm ERR! Please make sure you have the correct access rights
#13 81.98 npm ERR! and the repository exists.
#13 81.99 
#13 81.99 npm ERR! A complete log of this run can be found in:
#13 81.99 npm ERR! /home/node/.npm/_logs/2022-07-22T10_18_37_431Z-debug-0.log
------
executor failed running [/bin/sh -c npm ci]: exit code: 128
```

What should I do?


Answers:
author: Siriwudhi Sawaidee
body: The problem occurred because I use another user which isn't the root user in the Dockerfile, and that screwed up the ssh thing.

To solve this problem, add uid=\<user id of the user\> to the --mount=type=ssh command

```
RUN --mount=type=ssh,uid=<user id> npm ci
```

comments: author: Roopa Patel
body: Hi there I am trying to run Docker container and continually the container showing its restarting and running and then breaks and the restart. Can any one help me here please


author: Patrik S
body: Hello [@Siriwudhi Sawaidee](/t5/user/viewprofilepage/user-id/4992235) ,

Welcome to Atlassian Community!

The error message printed in the logs indicates the SSH key you are using to authenticate the git clone command does not have permissions to clone the repository :

```
#13 81.98 npm ERR! git@bitbucket.org: Permission denied (publickey).
```

In this case, could you please confirm :

* Are you running this docker build locally or in Bitbucket pipelines? If in Bitbucket pipelines, I would suggest taking a look at the blog post [Cloning another Bitbucket Repository in bitbucket pipelines](https://bitbucket.org/blog/cloning-another-bitbucket-repository-in-bitbucket-pipelines)
* Are you copying the **private** SSH key to your docker image in any of the previous steps of your docker file? If not, you will have to [COPY](https://docs.docker.com/engine/reference/builder/#copy) the private SSH to the path \~/.ssh/id_rsa inside your docker image so it will be used by git

  ```
  COPY <path to local ssh key>/my_key ~/.ssh/id_rsa
  ```

* The **public** ssh key you are using needs to [added in a bitbucket account](https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/#Step-3.-Add-the-public-key-to-your-Account-settings) that has access to the repository being cloned or added as an [access key](https://support.atlassian.com/bitbucket-cloud/docs/add-access-keys/) in that repository

If after following the suggestions above you are still facing the same error, please share the Dockerfile with us so we can help you investigate further.

Thank you, [@Siriwudhi Sawaidee](/t5/user/viewprofilepage/user-id/4992235) .

Kind regards,

Patrik S


Tags: cloud