git – 在docker文件中为ssh-agent添加私钥

我正在尝试为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

如果我运行上面提到的命令,这是输出.

enter image description here

最佳答案

Done this already,and my key is passphrase free right now but it’s still asking

然后……如果你没有与你的私钥相关联的密码,你应该摆脱Dockerfile行:

# check if ssh agent is running or not,run
RUN eval `ssh-agent -s` && ssh-add /ssh/id_rsa

如果您不必记住/缓存密码,则不需要ssh代理.

相关文章

最近一直在开发Apworks框架的案例代码,同时也在一起修复Apw...
最近每天都在空闲时间努力编写Apworks框架的案例代码WeText。...
在《Kubernetes中分布式存储Rook-Ceph部署快速演练》文章中,...
最近在项目中有涉及到Kubernetes的分布式存储部分的内容,也...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...