Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker NGINX - PHP-FPM Cross Container Permissions?

I'm setting up a wordpress stack and having cross file permissions.

When using docker-compose up permissions seem not to be a problem but when using local docker swarm and using docker stack deploy, nginx gives me a 403 for file permission errors. When inspecting both the nginx:alpine container and the wordpress:php7.1-fpm-alpine container, i do indeed see that the containers each have different permission, on the nginx side it marks the files inside var/www/html as owned by user and group id 82 while on the php7.1 they are owned by www-data.

How can I make sure permission is correct across containers? The files are being bind mounted from the host.

```

version: '3'
services:
  nginx:
    depends_on:
      - wordpress
    image: private/nginx
    build: 
      context: ./stack/nginx
    volumes:
      - "wordpress:/var/www/html"
    ports:
      - 80:80
  wordpress:
    depends_on:
      - mysql
    image: private/wordpress
    build: 
      context: ./stack/wordpress
    volumes:
      - "wordpress:/var/www/html"
    environment:
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: password
  mysql:
    image: mariadb
    volumes:
      - "mysql:/var/lib/mysql"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: password
volumes:
  wordpress:
    driver: local
    driver_opts:
        type: none
        o: bind
        device: "${PWD}/wordpress"
  mysql:

```

like image 574
PeaceBringer Avatar asked Feb 07 '18 10:02

PeaceBringer


1 Answers

For anyone else who comes across this question and has no solution, this is how I approached the situation.

I added the following to my dockerfile, it creates a new www-datagroup AND user with the same id as the id that is used for the www-data user 82 & group 82 in the php-fpm image.

RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1

To my docker file for nginx.

and in my nginx.conf i set the nginx worker user to the newly created ww-data user.

user www-data;
like image 146
PeaceBringer Avatar answered Nov 08 '22 23:11

PeaceBringer