我有一个应用程序,使用Git执行各种有趣的东西(如运行git clone和git push),我正在尝试停靠它.
我遇到了一个问题,虽然我需要能够在容器中添加SSH密钥以供容器"用户"使用.
我尝试将其复制/root/.ssh/,更改$HOME,创建一个git ssh包装器,但仍然没有运气.
这是Dockerfile供参考:
#DOCKER-VERSION 0.3.4
from ubuntu:12.04
RUN apt-get update
RUN apt-get install python-software-properties python g++ make git-core openssh-server -y
RUN add-apt-repository ppa:chris-lea/node.js
RUN echo "deb http://archive.ubuntu.com/ubuntu precise universe" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install nodejs -y
ADD . /src
ADD ../../home/ubuntu/.ssh/id_rsa /root/.ssh/id_rsa
RUN cd /src; npm install
EXPOSE 808:808
CMD [ "node", "/src/app.js"]
Run Code Online (Sandbox Code Playgroud)
app.js 像git一样运行git命令 git pull
我正在Windows Server 2016上运行的Jenkins 2.152中创建一个工作,需要从bitbucket.org上托管的git repo中提取.我通过git-bash测试了ssh密钥,所以我知道它有效并且没有密码短语.当我尝试使用与Jenkins完全相同的私钥时,我收到一条错误消息.
Failed to connect to repository : Command "git.exe ls-remote -h
git@bitbucket.org:mygroup/myrepo HEAD" returned status code 128:
stdout:
stderr: Load key
"C:\\Users\\JE~1\\AppData\\Local\\Temp\\ssh2142299850576289882.key": invalid format
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
凭据设置为
scope: Global
user: git
Private Key -> Enter Directly -> copy and past - generated by ssh-keygen -t rsa in gitbash
Passphrase: empty
ID: empty
description: bitbucket.org …Run Code Online (Sandbox Code Playgroud) 我正在尝试为angular cli项目编写一个docker文件,但我有一个外部依赖项,它是BitBucket上的私有仓库,所以我需要传递我的ssh密钥.我正在尝试使用ssh密钥--build-arg
现在的问题是,它没有将这些密钥添加到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
# …Run Code Online (Sandbox Code Playgroud) 我希望能够读取文件的内容~/.ssh/id_rsa并将其传递到图像的构建阶段。当我使用该命令docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)",然后尝试在构建期间在容器内回显该命令时,我变得空了。
RUN echo "$SSH_PRIVATE_KEY" > /priv_key \
&& cat /priv_key
Run Code Online (Sandbox Code Playgroud)
结果是
Step 6/14 : RUN echo "$SSH_PRIVATE_KEY" > /priv_key && cat /priv_key
---> Running in c8d6e3c88cd8
Removing intermediate container c8d6e3c88cd8
Run Code Online (Sandbox Code Playgroud)
在 dockerfile 中我有ARG SSH_PRIVATE_KEY.
但是当我使用虚拟文本时,docker build --build-arg SSH_PRIVATE_KEY="dummy text"我可以在日志中看到它。
这导致我的私钥格式无效,因为它是空的。
RUN echo "${SSH_PRIVATE_KEY}" >> /root/.ssh/id_rsa
我做错了什么或者没有做什么?谢谢
我目前正在尝试通过 dockerising 来部署我的 NodeJS API 并将其放到 EC2 上,但是我已经因为这个错误走到了死胡同: load pubkey "/root/.ssh/id_rsa": invalid format
我尝试过的事情
apt-get install openssl-client在 docker 中使用和转换私有 RSA 密钥(但显然我丢失了,apt-get所以我也尝试过apk这也不起作用......????)可疑的:
pubkey,但所有教程都指出使用我的pem密钥,该密钥是从我的 EC2 设置中生成的。所以也许我错过了一个pubkey?但我找不到任何材料另有说明。gitlab-ci.yml
image: docker:19.03.12
variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_DRIVER: overlay2
services:
- docker:19.03.0-dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
stages:
- build
- deploy
build:
stage: build
script:
# - docker build --tag $CI_REGISTRY/$CI_PROJECT_PATH:latest .
# - …Run Code Online (Sandbox Code Playgroud) docker ×4
ssh ×3
dockerfile ×2
git ×2
amazon-ec2 ×1
bitbucket ×1
containers ×1
docker-image ×1
gitlab-ci ×1
jenkins ×1
ssh-keys ×1