Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

File permission issues using fpfis/httpd-php-dev #37

Open
vever001 opened this issue Feb 28, 2020 · 1 comment
Open

File permission issues using fpfis/httpd-php-dev #37

vever001 opened this issue Feb 28, 2020 · 1 comment

Comments

@vever001
Copy link

Hello,

I'm having permissions issues every time files get created by the container and I need to chown the files to my host user to be able to edit them.

The container uses root (uid=0 gid=0) so when it creates files (using e.g: drush config:export or files created in sites/default/files and many other cases) I can't edit them on phpstorm running on my host machine with my current user "herve" (uid=1000 gid=1000).
I then need to sudo chown the files to my host user to be able to edit them - sudo chown herve:herve -R ...

If I'm not mistaken, this could be solved by creating a user in the container with matching uid and gid, and run shells as that user. Similar to how it's done in wodby/php.

Can you confirm you also have this behavior with file permissions? Or is it just me?
If so, is there perhaps already a consensus on having to chown every time files created by the container (which is a bit painful IMO) or is there something we can do to fix this?

Thank you,
Hervé

@vever001
Copy link
Author

vever001 commented Mar 2, 2020

For what it's worth, I created a user in a custom build context for now:

FROM fpfis/httpd-php-dev:7.2

# Create an "fpfis" user with given UID and GID (to use for bash and FPM).
# The UID and GID should match the ones from your host, running phpstorm.
ARG FPFIS_USER_ID=1000
ARG FPFIS_GROUP_ID=1000
RUN set -xe; \
  \
  # Delete existing user/group if uid/gid occupied.
  existing_group=$(getent group "${FPFIS_GROUP_ID}" | cut -d: -f1); \
  if [ -n "${existing_group}" ]; then delgroup "${existing_group}"; fi; \
  existing_user=$(getent passwd "${FPFIS_USER_ID}" | cut -d: -f1); \
  if [ -n "${existing_user}" ]; then deluser "${existing_user}"; fi; \
  \
  # Create or recreate the user and group.
  addgroup --gid "${FPFIS_GROUP_ID}" fpfis; \
  adduser --uid "${FPFIS_USER_ID}" --system --shell /bin/bash --group fpfis; \
  adduser fpfis www-data; \
  sed -i '/^fpfis/s/!/*/' /etc/shadow;

Then I use that user to run FPM:

web:
  build:
    context: ./resources/docker/images/web
  ...
  environment:
    DAEMON_USER: fpfis
    DAEMON_GROUP: fpfis
    ...

and login to the container:
docker-compose exec --user fpfis web bash

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant