Skip to content

Docker fatal: detected dubious ownership in repository at '/work' #226

@cto-xperdat

Description

@cto-xperdat

Running openapi-changes (v0.0.85) in Docker I found this git-related error:

$ docker run --rm -v $(pwd):/work pb33f/openapi-changes html-report . openapi.yaml

@@@@@@@   @@@@@@@   @@@@@@   @@@@@@   @@@@@@@@
@@@@@@@@  @@@@@@@@  @@@@@@@  @@@@@@@  @@@@@@@@
@@!  @@@  @@!  @@@      @@@      @@@  @@!
!@!  @!@  !@   @!@      @!@      @!@  !@!
@!@@!@!   @!@!@!@   @!@!!@   @!@!!@   @!!!:!
!!@!!!    !!!@!!!!  !!@!@!   !!@!@!   !!!!!:
!!:       !!:  !!!      !!:      !!:  !!:
:!:       :!:  !:!      :!:      :!:  :!:
 ::        :: ::::  :: ::::  :: ::::   ::
 :        :: : ::    : : :    : : :    :


🔗 https://pb33f.io/openapi-changes/
------------------------------------
openapi-changes version: latest | compiled: Tue, 29 Jul 2025 10:38:43 UTC

starting work.                                                                  
  ERROR   Stopped: cannot extract history received non-zero exit code from git for '.' when running "/usr/bin/git --no-pager log --pretty=%cD||%h||%s||%an||%ae --follow -n 5 -- openapi.yaml" (are you sure it's a git repo?): exit status 128 -- stderr: fatal: detected dubious ownership in repository at '/work'
          To add an exception for this directory, call:
          
                git config --global --add safe.directory /work

  DONE   completed processing                                                   

 WARNING  warnings reported during processing
⚠️  received non-zero exit code from git for '.' when running "/usr/bin/git --no-pager log --pretty=%cD||%h||%s||%an||%ae --follow -n 5 -- openapi.yaml" (are you sure it's a git repo?): exit status 128 -- stderr: fatal: detected dubious ownership in repository at '/work'
To add an exception for this directory, call:

        git config --global --add safe.directory /work

Error: received non-zero exit code from git for '.' when running "/usr/bin/git --no-pager log --pretty=%cD||%h||%s||%an||%ae --follow -n 5 -- openapi.yaml" (are you sure it's a git repo?): exit status 128 -- stderr: fatal: detected dubious ownership in repository at '/work'
To add an exception for this directory, call:

        git config --global --add safe.directory /work

  ERROR   received non-zero exit code from git for '.' when running "/usr/bin/git --no-pager log --pretty=%cD||%h||%s||%an||%ae --follow -n 5 -- openapi.yaml" (are you sure it's a git repo?): exit status 128 -- stderr: fatal: detected dubious ownership in repository at '/work'
          To add an exception for this directory, call:
          
                git config --global --add safe.directory /work

As a workaround I cloned this repo, I added to the Dockerfile the command RUN git config --global --add safe.directory /work and, using the custom built image, it works.

Here is the Dockerfile I used:

FROM golang:1.23-bookworm as builder

RUN mkdir -p /opt/openapi-changes

WORKDIR /opt/openapi-changes

COPY . ./

RUN go mod download && go mod verify
RUN go build -ldflags="-w -s" -v -o /openapi-changes openapi-changes.go

FROM debian:bookworm-slim
RUN apt-get update
RUN apt-get --yes install git
# ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
RUN git config --global --add safe.directory /work
# ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
WORKDIR /work
COPY --from=0 /openapi-changes /

ENV PATH=$PATH:/

ENTRYPOINT ["openapi-changes"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions