Avoid Permission Denied that occurs when developing Laravel with Docker

When developing Laravel locally with Docker instead of Laradock, Permission Denied failed to write / storage / logs. I will leave a workaround in this case.

Probably the cause of Permission Denied is that the UID and GID are different between the host and the client. When the configuration is Nginx> php-fpm by docker-compose, make it possible to specify any UID and GID for the Nginx user www-data in the Dockerfile on the php-fpm side as shown below. ..

Dockerfile


ARG PUID=1000
ARG PGID=1000

RUN echo "-> $PUID"
RUN echo "-> $PGID"

RUN groupmod -o -g $PGID www-data && \
    usermod -o -u $PUID -g www-data www-data

Insert the UID and GID of your Mac when docker-compose build.

$ docker-compose build --build-arg PUID=$(id -u) --build-arg PGID=$(id -g) app

Now the UID and GID of the host and client are the same.

bonus

$ (Id -u) could not be resolved correctly when the above command was set in the Makefile. It works well if you write as follows

Makefile


build_app:
	$(eval UID := $(shell id -u))
	$(eval GID := $(shell id -g))
	@docker-compose build --build-arg PUID=$(UID) --build-arg PGID=$(GID) app

Recommended Posts

Avoid Permission Denied that occurs when developing Laravel with Docker
General error: 1812 occurs with docker + laravel
I got a Permission Denied error when I put Laravel in Docker
Deploy with EC2 / Docker / Laravel
When requested access to the resource is denied when pushing with Docker
MalformedInputException that also occurs when writing
Create Laravel environment with Docker (docker-compose)
Build docker + laravel environment with laradock
Laravel development environment construction with Docker (Mac)
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Laravel + MySQL + phpMyadmin environment construction with Docker
Image flew when updating Docker with WSL2
When calling API with java, javax.net.ssl.SSLHandshakeException occurs
Display API specifications with Laravel + SwaggerUI + Docker
[Laravel] How to deal with out of memory error when composer require [Docker]
[Error resolution] Occurs when trying to build an environment for spring with docker
Solved DB connection and CORS problem when developing Laravel × Nuxt.js in Docker environment