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

前端之家收集整理的这篇文章主要介绍了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代理.

原文链接:https://www.f2er.com/docker/436045.html

猜你在找的Docker相关文章