I think I found a solution in your permission issues
Opened this issue · 0 comments
great series
problem with permissions is imho this:
permissions work with user id and not name
at least on my ubuntu system
my main user in my host system has user id 1001
echo $(id -u) # 1001 lets call this user myuser
it's because the system came with a user already installed, and I created my own user
the "first installed" user, get 1000, lets call it wronguser
I am speculating a bit here but
when you do
ls -l
you get, say
drwxr-xr-x 42 myuser myuser 4096 Aug 4 10:07 vendor
in reality in my case, what is there is actually (ive seen it)
drwxr-xr-x 42 1001 1001 4096 Aug 4 10:07 vendor
so your line in the dockerfile
RUN adduser -g ${PHPGROUP} -s /bin/sh -D ${PHPUSER}
doesn't do anything useful afaik.
because whatever user you add, and then define in config file, will have user id 1000
and then my host system will get in the mounted volume all files with permissions for user id 1000 for user: wronguser
system goes poof cause everything has wrong permissions now
solution 1 is, I guess, to change the user id of wronguser
to something else, and myuser
to 1000
I didnt feel comfortable doing that though, i dont know usermod that wall.
A workaround for me was to put
RUN apk add shadow && usermod -u 1001 myuser && groupmod -g 1001 myuser
into the php.dockerfile
e.g. complete php.dockerfile
FROM php:8-fpm-alpine
ENV PHPGROUP=myuser
ENV PHPUSER=myuser
RUN adduser -g ${PHPGROUP} -s /bin/sh -D ${PHPUSER}
RUN sed -i "s/user = www-data/user = ${PHPUSER}/g" /usr/local/etc/php-fpm.d/www.conf
RUN sed -i "s/group = www-data/group = ${PHPGROUP}/g" /usr/local/etc/php-fpm.d/www.conf
RUN apk add shadow && usermod -u 1001 myuser && groupmod -g 1001 myuser
RUN mkdir -p /var/www/html/public
RUN docker-php-ext-install pdo pdo_mysql
CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"]
that way all the log and session files will have the right user and permission
I use in the docker compose file as well
php:
build:
context: .
dockerfile: php.dockerfile
user: myuser
volumes:
- ./src:/var/www/html