docker - 将私有 ssh 密钥添加到 docker
问题描述
我正在尝试将我的 ssh 私钥添加到 docker,我的 Dockerfile 如下:
ARG key
RUN echo $key > panaxea-key
RUN chmod 600 panaxea-key
RUN eval $(ssh-agent -s) && ssh-add panaxea-key
控制台输出:
Step 10/14 : RUN echo $key > panaxea-key
---> Using cache
---> 8ee023dba45e
Step 11/14 : RUN chmod 600 panaxea-key
---> Using cache
---> b7c42a9c5268
Step 12/14 : RUN eval $(ssh-agent -s) && ssh-add panaxea-key
---> Running in 9895e087cea5
Agent pid 9
Enter passphrase for panaxea-key: The command '/bin/sh -c eval $(ssh-agent -s) && ssh-add panaxea-key' returned a non-zero code: 1
dario@dario-X750JB:~/Panaxea_Docker$
有什么建议吗?我的密钥没有密码
解决方案
如果您的密钥没有密码并且 ssh-add 要求您提供密码,这意味着 ssh-add 无法理解您的密钥文件。罪魁祸首是echo $key > panaxea-key
。您会看到该文件现在是一行文本,并且所有换行符都消失了。
改为使用echo "$key" > panaxea-key
。
这应该可以让它工作,但是关于在 docker 镜像中嵌入私钥的警告仍然存在。你如何解决这个问题取决于你想要完成什么,但我觉得这完全是一个不同的问题。
推荐阅读
- python - Python范围按位与边界解释
- python - 在一个变量 pyodbc 中运行多个 SQL Server 语句
- blogs - 博客文章省略 CSS
- nestjs - 具有包含 typeorm 方法的实体的种子数据库
- python-3.x - Chrome 自动化扩展程序已崩溃 - 在 Python 中使用 Selenium
- c - 如何从 Fortran 和 C 读取重定向的标准输入?(Linux/bash/gfortran/gcc)
- python - 有没有办法缩短 Mac (Python) 上的文件路径并减少数据帧?
- c - C数组在没有明显干预的情况下莫名其妙地改变了值
- r - 使用 R 的 bigrquery 库将数据追加/插入到 BigQuery 表中
- php - 我正在尝试在 PHP 中压缩一个数组