Git克隆不能与npm一起工作

我试图从一个Docker容器中的npm克隆一个私人的Git仓库,但得到一个错误的Permission denied (publickey)

我在主机上用这个命令生成了一个SSH密钥:

 ssh-keygen -t rsa -b 4096 -C "myname@mydomain.com" 

然后我把它添加到Bitbucket中, ssh-add -ed它,并用git clone进行testing,一切正常(在主机上)。 我也尝试npm install在我的项目文件夹和所有git克隆是好的。

我将id_rsaid_rsa.pub文件复制到另一个文件夹,并在执行docker run时将此文件夹挂载到/root/.ssh 。 现在的问题是,当试图从该私人Git仓库克隆时, npm install会给出拒绝权限的错误。

我用bash进入容器,手动尝试npm install ,但得到了同样的错误。 我通过运行eval "$(ssh-agent -s)"确保ssh-agent已启动,然后通过运行ssh-add ~/.ssh/id_rsa确保已添encryption钥。 然后我再次尝试,但同样的问题。

但是,如果在同一个容器中,我只是尝试一个常规的git clone ...那么它克隆就好了! 没有问题或任何事情。 我知道这是使用SSH密钥,因为如果我从Bitbucket中删除它,我得到一个权限被拒绝的错误。 然后,如果我重新添加到Bitbucket,它克隆罚款。

如何获得npm克隆正确? 在我使用的工作(在容器内)git clone命令是:

 git clone git@bitbucket.org:org/repo.git 

和npm回购依赖线是:

 "repo": "git+ssh://bitbucket.org/org/repo.git" 

完整的npm错误是:

 npm ERR! git clone ssh://bitbucket.org/org/repo.git Cloning into bare repository '/root/.npm/_git-remotes/ssh-bitbucket-org-org-repo-git-3f459951'... npm ERR! git clone ssh://bitbucket.org/org/repo.git Permission denied (publickey). npm ERR! git clone ssh://bitbucket.org/org/repo.git fatal: Could not read from remote repository. npm ERR! git clone ssh://bitbucket.org/org/repo.git npm ERR! git clone ssh://bitbucket.org/org/repo.git Please make sure you have the correct access rights npm ERR! git clone ssh://bitbucket.org/org/repo.git and the repository exists. 

git+ssh://bitbucket.org/org/repo.git ”看起来不像一个有效的ssh url。

git+ssh://git@bitbucket.org/{user}/{repository}.git ”是。

检查是否可以更改npm repo依赖关系url 。
(和/或npm install -S "git+https://username@github.com/orgname/repositoryname.git"