IleNea
IleNea

Reputation: 609

Unable to create the storage directory every time I clear the cache inside docker container

I am working at a Symfony 3.4 application, using docker. The problem is that after I enter in the container and do

php bin/console cache:clear

I always have this cache problem:

Unable to create the storage directory (/var/www/app/var/cache/dev/profiler).

I know that I can solve it by using:

chmod 777 -R var/cache/* var/logs/*

But after I clear the cache again, the problem is still there. There is a way to add just a single time the permissions, and after I clear the cache this issue to be solved?

Thank you.

Upvotes: 6

Views: 8226

Answers (2)

Kamafeather
Kamafeather

Reputation: 9845

Ensure that, in the Dockerfile, you create the cache directories needed by Symfony and set the right permission on them:

USER root
# RUN usermod -u 1000 www-data    # fix the UID
RUN mkdir -p var/cache/prod var/cache/dev var/cache/test var/log \
   && chown -R www-data:www-data var/ \
   && chmod -R ug+rwX var/

Then rebuild your image and the permissions on var should be fine by default and www-data should be able to write to the cache 😉

Upvotes: 7

mblaettermann
mblaettermann

Reputation: 1943

There are several ways to solve this. Personally I use to run my development docker containers as the same user I use locally.

So all files are only owned by one uid (1000 in my case)

Another way fixing it would be ACL flags on /var/cache to inherit directory rights on creation automatically. This is described here: https://symfony.com/doc/3.4/setup/file_permissions.html

Upvotes: 2

Related Questions