我正在尝试为angular cli项目编写一个docker文件,但我有一个外部依赖项,它是BitBucket上的私有存储库,因此我需要传递我的ssh密钥。我正在尝试使用--build-arg
传递ssh密钥
现在的问题是,它没有将这些密钥添加到ssh-agent并要求输入密码。
我正在使用此命令运行docker build -t ng-2-docker/client --build-arg ssh_prv_key="$(cat ~/.ssh/id_rsa)" --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa)" .
这是我的docker文件
ARG ssh_prv_key
ARG ssh_pub_key
# Use an official Node runtime as a parent image
FROM node:8.9.4
# Specify working directory in docker container
WORKDIR /app
# Authorize SSH Host
RUN mkdir -p /ssh/
RUN chmod 0700 /ssh
# Add the keys and set permissions
RUN echo "$ssh_prv_key" > /ssh/id_rsa && echo "$ssh_pub_key" > /ssh/id_rsa.pub && chmod 600 /ssh/id_rsa && chmod 600 /ssh/id_rsa.pub
# add bitbucket to known hosts
RUN ssh-keyscan bitbucket.org > /ssh/known_hosts
# Copy SSH key to temp folder to pull new code
# ADD ~/.ssh/id_rsa /tmp/
# RUN ssh-agent /tmp
RUN ls -la /ssh
# check if ssh agent is running or not, if not, run
RUN eval `ssh-agent -s` && ssh-add /ssh/id_rsa
# Copy local files into the containers working directory
COPY package.json /app
# Install dependencies inside container
RUN npm i
# Copy local files into the containers working directory
COPY . /app
# Execute Process
CMD ["npm", "docker:rogers:local"]
# Remove ssh key from temp
# RUN rm /tmp/id_rsa
RUN rm -rf /ssh
# expose port
EXPOSE 4200
字符串
下面是运行上面提到的命令的输出。
x1c 0d1x的数据
4条答案
按热度按时间0tdrvxhp1#
我花了几天的时间来解决同样的问题。ssh-keygen -p确保密码为空,但我需要在Dockerfile中添加ssh-agent和ssh-add,以便能够从私有仓库中提取。我的几个同龄人告诉我,他们能够使它工作;我会复制他们所拥有的,但仍然会被要求输入密码。最后我遇到了this issue。在逐行手动输入rsa键并看到它成功后,我意识到这是因为我正在构建图像并通过make目标传递键,而Makefile正在将换行符处理为空格。最终,这只是一个更新key如何作为参数cat的问题,以便它作为bash运行,而不是保留换行符。
下面是我的Makefile中的build命令:
字符串
我还将注意到我需要包括
型
我的一个Dockerfile RUN命令
uklbhaso2#
我已经这样做了,我的密钥现在没有密码但它仍然在询问
然后......如果你没有与私钥相关联的密码,你应该删除Dockerfile行:
字符串
如果您不需要记住/缓存密码,则不需要ssh代理。
0pizxfdo3#
从你的截图中可以看出,git-ssh客户端并没有询问你的bitbucket密码。您的私钥文件使用密码进行加密。要使用私钥,ssh需要密码。
一个选项是从私钥中删除密码。您可以使用ssh-keygen编辑您的私钥:
字符串
Source用于ssh-keygen
0lvr5msh4#
其中token.txt是base64编码的
字符串