I'm building a docker environment for a Symfony application. I have a container per application with an attached data only container for the web root that is linked to the application server. As part of the security hardening for the infrastructure these data containers are set to read only, to prevent any remote code exploits. Each application then also has a side car container that allows logs to be written to.
Symfony currently writes the cache to the default cache_dir
location of
${web_root}/app/cache/${env}
Which is in the read-only data container
when trying to boot the application I get this error
Unable to write in the cache directory
Obviously as its in the write only container this will happen
I've set my log_path is set in parameters outside the read-only container in the read-write sidecar logging container of
/data/logs/symfony
which works fine.
I've read the Symfony cookbook on how to over ride the directory structure but it only advises on how to do this in AppKernal.php
which I don't want to do as the paths may change dependant on if its in a local/uat/prod
environment.
We feed Symfony different parameters from our build server depending on the environment we are deploying to so it makes sense to put this config in here.
does anyone know if its possible to override the cache dir in config rather than editing AppKernal.php
I'm creating the cache file outside the container and using
-v
to mount the directory into the container$DIR is the current location
htdocs where the webfiles are
Then make sure that the container is allowed to write into
cache_folder
. The advantage is that you're not loosing any data if you recreate the container. This will also overwrite the folder/var/www/html/app/cache
Another way you can do this is inside every container, but loose the setting with every restart
Here's a simplified example of a docker-compose yml file i'm using, with a read only parent data container with 2 sidecar containers for caching and logging with :rw access that overrides a path that is contained with the read-only parent path