Skip to content

Conversation

@nathanbarrett
Copy link
Contributor

Add safe.directory for /var/www/html to silence Git’s “dubious ownership” warnings in Sail images

image

This PR adds one line to each Sail PHP Dockerfile (8.0–8.4):

RUN git config --global --add safe.directory /var/www/html

Why this is needed

When working inside Sail containers, Git often prints the warning:

fatal: detected dubious ownership in repository at '/var/www/html'

This is noisy and distracting during normal local development (e.g., running Composer scripts or simple git status), because the container’s active user/UID may not match the on-disk ownership of /var/www/html. Marking the working directory as a safe Git directory removes the warning without changing how folks use Sail day-to-day.

What causes the “dubious ownership” warning

In April 2022, Git shipped a security fix hardening for CVE-2022-24765. As part of that fix, Git refuses to operate in a repository if the current user differs from the repository owner, unless the path is explicitly trusted via the safe.directory setting. This protects users on multi-user systems from configs/hooks in repos they don’t own.

The behavior is documented in Git’s manuals: by default, Git will not run in repos owned by someone else; you can opt-in specific paths with safe.directory.

In containerized dev environments this mismatch is common (different UIDs inside the container vs. the mounted volume), which is why Sail users see the warning frequently.

Why this is safe for Sail

Sail is explicitly a local development environment—not a production runtime—and is intended to help developers get a Laravel app running with Docker on their own machine. Marking /var/www/html (the working dir inside Sail) as “safe” only suppresses the ownership check for that one path inside the container. It does not weaken Git’s checks globally, nor does it add any new privileges; it simply acknowledges that this specific, local dev path is trusted.

@taylorotwell taylorotwell merged commit f908e3a into laravel:1.x Aug 27, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants