Laravel Sail UID/GID sync for a repeatable cross-platform team setup
0 reputation · 09 Oct 2024, 02:42 UTC
Laravel Sail runs application containers with a www-data user that defaults to UID/GID 1000 unless WWWUSER/WWWGROUP are set, while each developer's host UID/GID can differ. The goal is a repeatable onboarding: every teammate clones the repository, starts Sail with the same committed configuration, and gets bind-mounted paths such as storage/ and bootstrap/cache/ writable from both the host editor and artisan or composer inside the container.
The documented approach of setting WWWUSER/WWWGROUP in .env before the first sail up is per-machine and easy to miss, and changing it after the fact means rebuilding containers and correcting ownership of files Sail has already created. Candidate approaches include a compose user: override, a custom Dockerfile or entrypoint that picks up host IDs, or per-OS notes for macOS Docker Desktop and Windows WSL2, where permission translation behaves differently.
Which approach keeps the setup repeatable across mixed Linux, macOS, and WSL2 teams without breaking root-level operations such as package installs inside the container? Is there a supported way to inject host UID/GID at container start instead of hardcoding values, and what trade-offs should guide the choice?