Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker PHP permissions

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
like image 778
Max Heyer Avatar asked Jun 23 '17 08:06

Max Heyer


1 Answers

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
like image 160
Tania Petsouka Avatar answered Sep 20 '22 03:09

Tania Petsouka