laravel / sail

Docker files for running a basic Laravel application.
https://laravel.com/docs/sail
MIT License
1.65k stars 470 forks source link

Allow building sail to run PHP as root #677

Closed vmsh0 closed 6 months ago

vmsh0 commented 6 months ago

Hi,

Today, I tried running Sail in a rootless Podman container, and the experience was less-than-ideal. You might better recognize the class of issues as being similar to Docker Desktop - this would be precisely right: it's the same all over again.

The reason boils down to the follow: the image, as it is laid out currently, has its entrypoint running as root, and its main functionality (i.e. php) running as the sail user. This means that root inside the container is the host user I'm using to run the container, and sail is some random UID.

Some relevant supporting documentation and references to previous issues:

The proposed proof-of-concept patch simply allows setting the $SUPERVISOR_PHP_USER env variable to run PHP in the container as root. Users should be instructed about this by the "getting started" documentation, to avoid spending an evening figuring it out (or not) like I just did.

In my opinion this is the only valid long-term solution for rootless containers, as:

This will effectively make PHP have the permissions and capabilities of the launching user, which imho is the standard expectation for a dev environment. Furthermore, in a world where people don't just go around launching containers as root, this would also be a sensible default setting, but since the real world is the insurmountable single point of truth I won't advocate for that.

So, to recap:

muriloloffi commented 6 months ago

Well done and thank you @vmsh0. Your explanation and PoC were helpful to me.

vmsh0 commented 6 months ago

Thank you for merging this, I'm glad to see it's useful to people.

Please, help me with the next steps to improve this: