【问题标题】:how to change git config in docker如何在docker中更改git配置
【发布时间】:2022-01-07 08:18:35
【问题描述】:

克隆我的 git repo 后,我正在尝试更改 docker 容器中的钩子路径,这是我的简单 Dockerfile

FROM node:lts-alpine

WORKDIR '/app'

COPY package.json .
RUN npm install

COPY . .

RUN apk update && \
    apk add git

RUN git config core.hooksPath .husky
RUN git config --list
CMD ["npm", "run", "start"]

在构建时,git config --list 打印出更改后的 hookPath。但是在构建完成后,当我在容器中手动运行命令时,git config --list 显示没有任何变化。

你能解释一下为什么会发生这种情况吗?没有办法改变容器中的 git config 吗?

【问题讨论】:

  • 你是如何在容器中运行命令的?
  • 我对此有点困惑:图像通常包含应用程序代码的不可变副本,这意味着代码不会改变,这意味着容器内没有任何git commit,这意味着钩子永远不会触发。您需要在非 Docker 开发环境中进行设置吗?

标签: git docker githooks git-config


【解决方案1】:

我的经历不同,我重现了您的预期行为:

FROM docker.io/node:lts-alpine

RUN apk update && \
    apk add git

COPY . .

RUN git config core.hooksPath .husky
RUN git config --list

然后:

docker build \
--tag=70172374 \
--file=./Dockerfile \
.

产量:

Sending build context to Docker daemon
Step 1/6
Step 2/6
Step 3/6
Step 4/6 : RUN git config core.hooksPath .husky
Step 5/6 : RUN git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.hookspath=.husky
Successfully built c7e7f16f6698n.com 443
Successfully tagged 70172374:latest

然后:

docker run \
--interactive --tty --rm \
70172374:latest \
  ash -c "git config --list"

产量:

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.hookspath=.husky

【讨论】:

  • 感谢您的回答。我刚刚意识到我在 docker-compose 文件中映射了像 .:/app 这样的卷,它覆盖了本地 git 配置文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-29
  • 2015-06-16
相关资源
最近更新 更多