我正在尝试在Docker容器中运行bower install
,该命令已作为docker-compose.yml
中的一个命令传递。
docker-compose.yml
中相关的代码:
services:
assets:
build: ./src
command: >
sh -c '
bower install --allow-root;
'
bower.json
包含以下依赖:
{
"name": "projectname",
"version": "version",
"dependencies": {
"remote-repo": "ssh://git@remoterepo.url/repo.git#branch"
}
}
这个远程仓库是私有的。主机已经具备了正确的SSH凭证,可以从远程拉取代码。
我尝试了4到5种不同的方式,将主机的SSH凭证传递给Docker容器,但每次尝试都会出现相同的错误信息:
docker_1 | bower repo#branch ECMDERR Failed to execute "git
ls-remote --tags --heads ssh://git@remoterepo.url/repo.git", exit code
of #128 Host key verification failed. fatal: Could not read from
remote repository. Please make sure you have the correct access
rights and the repository exists.
当我直接在容器中使用
exec
命令并尝试进行git克隆时,会询问我是否确定要将远程主机添加到known_hosts,并要求输入我的ssh密钥的密码(这是第一次连接到远程主机时的预期行为)。我按照此stackoverflow响应中的步骤尝试绕过提示:https://dev59.com/D2Ag5IYBdhLWcg3wm8D7#23411161 甚至通过ssh添加了我可以添加的所有步骤,将这些步骤添加到我的Dockerfile下的RUN命令中:https://serverfault.com/questions/132970/can-i-automatically-add-a-new-host-to-known-hosts/316100#316100 现在,我的安装脚本(运行
docker-compose up
等其他内容)包括以下行:cp $HOME/.ssh/id_rsa src/id_rsa
我已确认id_rsa正确地被复制到Dockerfile所在的目录中(具体而言,是我的应用程序内的src
目录)
我的Dockerfile包含以下内容:
# Make ssh dir
RUN mkdir /root/.ssh/
# Copy over private key, and set permissions
ADD id_rsa /root/.ssh/id_rsa
# Create known_hosts
RUN touch /root/.ssh/known_hosts
# Add remote's key
RUN ssh-keygen -R remoterepo.url
RUN ssh-keygen -R remoterepoIP
RUN ssh-keygen -R remoterepo.url,remoterepoIP
RUN ssh-keyscan -H remoterepo.url,remoterepoIP >> /root/.ssh/known_hosts
RUN ssh-keyscan -H remoterepoIP >> /root/.ssh/known_hosts
RUN ssh-keyscan -H remoterepo.url >> /root/.ssh/known_hosts
有没有办法让位于Docker容器中的Bower访问私有远程仓库?我感觉我已经尝试了所有方法(而且这周一直在尝试不同的方法)。