我正在使用Docker设置Node.js服务的部署.
我所拥有的Dockerfile是从网络上的各种示例中拼凑而成的.
Dockerfile的目录包括:
> Dockerfile
> id_rsa
> start.sh
这是Dockerfile:
FROM ubuntu:13.10
# make sure apt is up to date
RUN apt-get update
# install npm,git,ssh,curl
RUN apt-get install -y npm git git-core ssh curl
RUN mkdir /nodejs && curl http://nodejs.org/dist/v0.10.31/node-v0.10.31-linux-x64.tar.gz | tar xvzf - -C /nodejs --strip-components=1
# Fixes empty home
ENV PATH $PATH:/nodejs/bin
ENV HOME /root
# SSH SETUP
RUN mkdir -p /root/.ssh
ADD id_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "IdentityFile /root/.ssh/id_rsa" >> /root/.ssh/ssh_config
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
ADD start.sh /tmp/
RUN chmod +x /tmp/start.sh
CMD ./tmp/start.sh
设置完成后,start.sh运行,我遇到私有Node.js服务所具有的私有NPM依赖问题.这就是start.sh正在做的事情:
cd /tmp
# try to remove the repo if it already exists
rm -rf MediaFX; true
git clone https://
在ExampleRepo的package.json中,我们导入了一个私有模块,如下所示:
"dependencies": {
"scribe": "git+ssh://git@github.com:Company/PrivateDep.git"
},
当npm install进入此repo时,它会输出以下日志:
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-InBoxAppCo-scribe-git-abae334a'...
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git Permission denied (publickey).
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git fatal: Could not read from remote repository.
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git Please make sure you have the correct access rights
npm ERR! git clone git@github.com:InBoxAppCo/scribe.git and the repository exists.
npm ERR! Error: `git "clone" "--mirror" "git@github.com:InBoxAppCo/scribe.git" "/root/.npm/_git-remotes/git-github-com-InBoxAppCo-scribe-git-abae334a"` Failed with 128
npm ERR! at ChildProcess.cpclosed (/usr/share/npm/lib/utils/exec.js:59:20)
npm ERR! at ChildProcess.EventEmitter.emit (events.js:98:17)
npm ERR! at Process.ChildProcess._handle.onexit (child_process.js:789:12)
npm ERR! If you need help,you may report this log at:
npm ERR!
我认为,由于私有Node服务的git克隆工作正常,它的任何私有NPM依赖项都可以顺利安装.
我相当肯定我的SSH设置有缺陷(并且它没有表现出自己,而git克隆私人父母回购)因为我在链接中添加了用户名和密码.但是,我不确定,并希望得到一些关于如何正确执行此操作的指导.
最佳答案
git clone https://< username>:< password> @ github.com / company / ExampleRepo.git
工作,因为您传递用户名和密码并通过https进行
"dependencies": {
"scribe": "git+ssh://git@github.com:Company/PrivateDep.git"
},
失败,因为您通过ssh直接连接,而Docker不会从主机上执行任何ssh代理转发.
不幸的是,它看起来不像npm支持任何url格式发送用户名和密码,如克隆线:https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
你必须将你的ssh密钥添加到docker容器中(Not Reccomended)
或者做一些时髦的事情,比如从主机上分享你的SSH_SOCKET,如: