Laravel app: permission denied to write on mounted volume
I am using
serversideup/php:8.3-unit
as docker image in my application. The home directory of my application is /var/www/html/
and I am mounting the volume to /var/www/html/storage/app/public
which is where the files that are uploaded to my application are stored.
I already set the environment variable RAILWAY_RUN_UID=0
but I have permission issues to write to the mounted volume.
The container is running as a non-privileged user www-data
but i still have the following error:
This is the code that generates the error:
Solution:Jump to solution
Because I'm using a docker image that by default runs as a non-privileged user
www-data:www-data
or 33:33
, it's necessary to change the owner of the mounted volume after starting the container.
To achieve this, I added a script in /etc/entrypoint.d/99-starting-hook.sh
with the following content:
```sh...11 Replies
Project ID:
e2d6c1c6-c741-45c3-b553-98603eaddb38
e2d6c1c6-c741-45c3-b553-98603eaddb38
Hey, can you send your dockerfile?
can you try without switching back to the non root user?
Yes, trying...
Same problem.
Can i specify RAILWAY_RUN_UID=33 to make it the same uid as the image?
nope, the volume is mounted as root, you would need to chown the volume mount before starting your app
like what is done here - https://github.com/railwayapp-templates/elasticsearch/blob/main/entrypoint-new.sh
The problem has been solved, I will share my solution.
Solution
Because I'm using a docker image that by default runs as a non-privileged user
www-data:www-data
or 33:33
, it's necessary to change the owner of the mounted volume after starting the container.
To achieve this, I added a script in /etc/entrypoint.d/99-starting-hook.sh
with the following content:
This is my final Dockerfile:
There is no need to add the RAILWAY_RUN_UID=0
environment variable because the volume is already owned by the www-data
user.
If you are using serversideup/php:8.3-unit
you must add the following environment variable:
AUTORUN_ENABLED=true
This will run php artisan storage:link
after starting the container.perfect, glad i could help!