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"