[英]Copying local git config into docker container
我同时使用 docker 和 docker-compose 来托管大部分是 LAMP 堆栈。 我希望能够在我的一个容器中使用 git,而不会在构建后在推送时询问我的 user.email 和 user.name。 以及我的 push.default 和分支设置等其他内容。 有什么好方法可以让 docker 或 docker-compose 将git config --list
的结果复制到容器中的文件中,然后我可以将其与我的入口点一起使用来设置 git config。
是否有任何好方法让docker或docker-compose将git config --list的结果复制到容器中的文件中,然后我可以使用我的入口点来设置git配置。
你真的不需要这样做来实现你的目标,有一个发件箱解决方案:
对于运行git的主机, git config --list
所有内容都存储在文件中:
git config --system
配置它们,它们将存储在/etc/gitconfig
git config --global
来配置它们,它们将存储在~/.gitconfig
因此,您只需要将文件挂载到容器,然后就可以在主机上重用git configure。
如下,FYI。
如果主机使用--global
来配置git:
docker run --rm -it -v ~/.gitconfig:/etc/gitconfig your_image_with_git git config --list
输出: user.name=xxx
如果主机使用--system
配置git:
docker run --rm -it -v /etc/gitconfig:/etc/gitconfig your_image_with_git git config --list
输出: user.name=yyy
对于docker-compose
,您只需配置volumes
来定义安装。
对于docker-compose
,这对我来说效果很好(基于@atline的回答)
volumes:
- "~/.gitconfig:/etc/gitconfig"
我假设您希望能够在容器中使用git,但同时又不想一次又一次地输入用户名和密码?
我能想到的方法是在Dockerfile中添加git config
命令。
原因是您将以明文方式提供密码,无论如何。
所以,我的建议是将这些行添加到Dockerfile中。
RUN git config --global user.name "your username"
RUN git config --global user.password "your password"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.