Symfony docker resolution issues for cache files

I have a symfony setup for docker with docker-compose, which works fine, except when I run the cache: clear from the console, the web server cannot access the files.

I can get around the permission problem with uncommenting umask (0000); in the console and web / app_dev.php, but I would like to run symfony as recommended.

What I am doing is deploying docker-compose up containers
Then I enter the container. The container contains apache, php and code through the amount of data.

 docker exec -i -t apache_1 /bin/bash 

Apparently, I am logged in as root, and then when I run

 app/console cache:clear 

all files in the cache belong to the root user. www-data, since the web server user no longer has access to files anymore.

I can also get around this by logging in as www-data, and then the files created by the cache: clear belong to www-data, and the web server can access it.

 docker exec -u www-data -i -t apache_1 /bin/bash 

But this has the disadvantage that I do not land in bash, but in / usr / sbin / nologin and does not have such things as bash_history, etc.

Searching around I found this as part of a Docker file to solve a resolution problem, but that did not affect me.

 RUN usermod -u 1000 www-data 

If I understand correctly, this switches user 1000 to www-data, but as root, when I enter the container, this does not work. I suppose.

So, why am I root when I enter the container and how does it work?

docker-compose.yml:

 proxy: image: jwilder/nginx-proxy:latest volumes: - /var/run/docker.sock:/tmp/docker.sock:ro ports: - "80:80" elastic: build: docker/elasticsearch ports: - "9200:9200" volumes: - data/elasticsearch:/usr/local/elasticsearch/data apache: build: docker/apachephp environment: - VIRTUAL_HOST=myapp.dev volumes: - ./code:/var/www/app - ./dotfiles/.bash_history:/.bash_history - ./logs:/var/www/app/app/logs links: - elastic expose: - "80" 
+5
source share
1 answer

I would think that changing www-data userid to your host user id is a good solution, since permissions for the host user are pretty easy to configure.

 #change www-data`s UID inside a Dockerfile RUN usermod -u [USERID] www-data 

default user id 1000 for most linux systems afaik ... 501 on mac
you can run id -u on the main system to find out.

Then you can enter the container to run symfony commands as www-data p>

docker exec -it -u www-data [CONTAINER] bash

I was wondering how you can dynamically set the user id in the container assembly. I assume passing it through --build-arg to docker-compose would be a way

 docker-compose build --build-arg USERID=$(id -u) 

... but have not yet been able to access this var in the Docker file.

+4
source

Source: https://habr.com/ru/post/1241245/


All Articles