21
loading...
This website collects cookies to deliver better user experience
docker-compose up -d
, everything in the terminal would return okay and I didn't see any errors pop up during the build.artisan
or composer
commands in the browser through the Docker container(s). Making this even more frustrating, visiting direct images or compiled assets would return just fine.php
on a user called www-data that has an ID of 1001. When trying to modify files under the application's directory, like writing to the cache or saving an image, the difference in those two ownerships causes a conflict in the permissions and the process errors out.laravel
with the same group id as my local machine's group that owns my app's files. This is important. I also do the same thing with the user, creating a user called laravel
. RUN addgroup -g ${GID} --system laravel
RUN adduser -G laravel --system -D -s /bin/sh -u ${UID} laravel
-g
pass in a group ID that we want to attach to this new group${GID}
an environment variable for the group ID passed in through Docker Compose (I'll get to this soon)--system
it's a system-wide grouplaravel
the name of the group we're creating-G
the name of the group we want to assign this user to, an in our case it's the group we just created--system
it's a system-wide user-D
don't create a password for this user-s /bin/sh
give it the Alpine Linux shell-u ${UID}
pass in a user ID that we want to attach to this new user, and like the group ID it's coming through an environment variablelaravel
the name of the user we're creatingwww-data
. I could copy over a modified php.ini file, but since it's just a few character changes I decided to use a couple of commands in that same Dockerfile:RUN sed -i "s/user = www-data/user = laravel/g" /usr/local/etc/php-fpm.d/www.conf
RUN sed -i "s/group = www-data/group = laravel/g" /usr/local/etc/php-fpm.d/www.conf
id -u
and id -g
to get both of those, assuming that the current user logged in is who owns the files for the Laravel app I'm working on.ENV UID=501
ENV GID=20
ARG UID
ARG GID
ENV UID=${UID}
ENV GID=${GID}
docker-compose.yml
file like this:php:
build:
context: .
dockerfile: php.dockerfile
args:
- UID=${UID:-1000}
- GID=${GID:-1000}
:-
separator means, a default value).echo $UID
and echo $GID
. If you see values for both, great! If you don't, you'll need to export them by running the following command:export UID=$(id -u) && export GID=$(id -g)
docker-compose up -d --build
php
process will then use the new laravel user to run as, meaning that any write access to the app filesystem should be granted since the defining user attributes for the permissions now match.