I set up the symfony-docker configuration in a sulu application. Everything works fine in development thanks to the bind mount of the app root directory. But in production, the media files uploaded by the user are not persisted when containers are restarted.
I tried adding a volume like that, in docker-compose.yml
(in the php
service or in the caddy
service):
services:
php:
volumes:
- uploads:/srv/app/public/uploads
...
volumes:
uploads:
But then, the thumbnails are not generated when I upload an image. And, when using the image in a template, I get the following error when the media is fetched:
Failed to create "/srv/app/public/uploads/media/homepage-1920x/04": mkdir(): Permission denied
CodePudding user response:
Thumbnails are not generated on upload they are generated the first time you request them. This saves a lot of space as not every image is needed in every size.
An example docker setup for development only can be found here:
https://github.com/dunglas/symfony-docker/blob/main/docker-compose.yml
In a normal linux setup you need to make sure that your webserver user / php fpm user is allowed to access the public/uploads
directory this is done via:
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var public/uploads
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var public/uploads
See also:
https://docs.sulu.io/en/latest/cookbook/web-server/nginx.html#linux
Maybe something similar is required when using caddy or there is another way to tell caddy in docker how to set the correct permissions for that directory.