7

My php container does not have the permissions to write cache on the mounted volume.

docker-compose.yml:

version: '2'
volumes:
    database_data:
        driver: local
services:
    php:
        build: ./docker/php/
        expose:
            - 9000
        volumes:
            - ./public:/var/www/html
        working_dir: /var/www/html
    nginx:
        image: nginx:latest
        depends_on:
            - php
        ports:
            - 80:80
        volumes:
            - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
        volumes_from:
            - php

docker/php/Dockerfile:

FROM php:7.0-fpm

RUN docker-php-ext-install pdo_mysql \
    && docker-php-ext-install json


# Permission fix
RUN usermod -u 1000 www-data
Max Heyer
  • 135
  • 2
  • 8

3 Answers3

8

You need to adapt the uid & gif of www-data to match the ownership of the files. Inside your php's Dockerfile:

RUN sed -ri 's/^www-data:x:82:82:/www-data:x:1000:50:/' /etc/passwd
RUN chown -R www-data:www-data /var/www/html
Tania Petsouka
  • 1,388
  • 1
  • 9
  • 20
0

Do you use it under Mac? Try to append this line in your php Dockerfile: RUN usermod -G staff www-data

István Döbrentei
  • 948
  • 10
  • 20
0

Another approach is to use the chown flag when copying, as stated here.

COPY --chown=<user>:<group> ...
John White
  • 917
  • 1
  • 12
  • 26