这实际上是我之前的一个问题 one .
我正在尝试使用 docker 托管个人笔记网络服务,并希望备份该服务生成的数据(我的笔记)。 目前,我计划使用 git 提交、 pull 和推送到一个存储库以达到我的目的。
要执行 git pull 和 push,我的 docker 镜像需要托管我的凭据。实现这一目标的最简单而安全的方法是什么?
到目前为止我做了什么:
- 我选择
Alpine
作为我的服务图像的基础图像。 - 因为我只需要 git 的凭据,所以我认为将 git 凭据助手放入图像中可能会解决我的问题。我可以在构建期间将凭据保存到助手,并在运行时使用它们。
- 根据 this article,我在谷歌上搜索了一会儿,决定使用
libsecret
作为我的 git 凭证助手。 . - 我已经安装了
libsecret
并将我的 git 凭据助手设置为git-credential-libsecret
但是,到目前为止,我无法使 git-credential-libsecret
发挥作用。以下是我遇到的几个问题:
首先,我测试了
git-credential-libsecret get
,得到如下错误:CRITICAL **: could not connect to Secret Service: Cannot spawn a message bus without a machine-id: Unable to load /var/lib/dbus/machine-id or /etc/machine-id: Failed to open file */var/lib/dbus/machine-id*: No such file or directory
- 我(可能?)通过安装
dbus
并运行dbus-uuidgen >/var/lib/dbus/machine-id
解决了这个问题
- 我(可能?)通过安装
然后我尝试再次运行
git-credential-libsecret get
。这一次,它报告说:CRITICAL **: could not connect to Secret Service: Cannot autolaunch D-Bus without X11 $DISPLAY
- 我尝试安装
dbus-x11
并运行dbus-launch --sh-syntax
( from here ) 但这次没有成功。错误继续。
- 我尝试安装
最后,我想知道:
- 我的方向是否正确(使用 git credential helper)来实现我的目标?
- 如果是这样,我该如何解决 X11 问题?
- 是否有任何其他快速和干净的方法来备份带有版本控制的 docker 中的数据?
最佳答案
如果您的 git 提供商支持使用公钥的 ssh,我认为最简单的方法是切换到它们。您也不必复制密码。
你需要:
- 将 ssh 客户端添加到您的 docker 镜像
- generate an ssh key并将其复制到图像中。不需要
ssh-agent
部分 - register the key to the provider
关于linux - 如何将凭证烘焙到 git 的 docker 镜像中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48237435/