markshust / docker-magento

Mark Shust's Docker Configuration for Magento
https://m.academy/courses/set-up-magento-2-development-environment-docker/
MIT License
2.53k stars 997 forks source link

Change user id of user running php-fpm #656

Closed enx1998 closed 2 years ago

enx1998 commented 2 years ago

Description With Linux, files created from phpfpm are owned by another user rather than the one who is running containers, resulting in permission errors (for example writing files in app/etc directory). Is it possible to change the id of the user running php-fpm to the same one running containers?

Thanks, ENx

markshust commented 2 years ago

Yes, it's possible to set the id of the user as it is defined at https://github.com/markshust/docker-magento/blob/master/images/php/7.4/Dockerfile#L4

I've never had to do this, so I'll pass this on to @shochdoerfer who implemented this update. Stephan, can you enlighten us on how to set the ids to something else? 😄 Thanks

shochdoerfer commented 2 years ago

Sure.

In this case, you can't rely on the pre-built images, you need to build the images on your own. That means you need to store the Dockerfile somewhere in your project directory and instead of using the Doker Image name, you need to reference the Dockerfile:

phpfpm:
build:
  context: docker/phpfpm
  dockerfile: Dockerfile
  args:
    - APP_ID

When you build the image - we added this extra step to the bin/setup script - you would run a command like this:

APP_ID=$(id -u) docker-compose build phpfpm

The command would set the APP_ID as the id of the current Linux user. If you want to set it to a different id, pass it as an argument.

Hope that helps.

@markshust Just realized that we also set the APP_ID in the nginx container. Not sure if that is really needed, can send you that as a PR as well. What do you think?

markshust commented 2 years ago

@shochdoerfer since files are mounted in the same fashion in both phpfpm and app containers, I think that would be a good idea 👍

shochdoerfer commented 2 years ago

@markshust done https://github.com/markshust/docker-magento/pull/658

@enx1998 you might be interested in the mentioned PR as well.

enx1998 commented 2 years ago

@shochdoerfer thanks for your reply, I did not realise there was the possibility to build the container by setting the user id running php-fpm. I think that the #658 is also useful, thanks.

Bye ENx

markshust commented 2 years ago

@enx1998 merged this in 👍 I'll compile a new build of nginx & php images shortly.

markshust commented 2 years ago

Images have been re-built with the last release of docker-magento.