0

The question is simple, yet the answer not so much I suppose.

Question

How do I or rather what is the best way of setting up write-access for my php-fpm container using docker without giving the process root-level access?

My thoughts

For now, the php-engine cannot write / modify directories and files. I read some articles about how to do something like this. Unfortunately, some were outdated, some contained hard to follow instructions i.e. unclear where to put snippets etc. In the end none of them seem to work for me.

I know that this has to do with the user-privileges and this is probably the solution to this issue. On php-fpm they say you can add some environment variables and it should setup a pre-defined user, which hopefully does just give me the correct permissions – maybe not. I never worked with linux systems so far and I really struggle with such an assumably basic task.

Current state

I am using a

docker-compose.yml
file. I also have added a
PHP.Dockerfile
and
nginx.conf
which I have linked to the container.

Setup

docker-compose.yml

			
version: "3.9"
services:
    nginx:
        container_name: webshop_nginx
        image: nginx:latest
        restart: unless-stopped
        tty: true

        ports:
            - "8080:80" # default
            - "443:443" # ssl

        volumes:
            - ../app:/app
            - ./nginx.conf:/etc/nginx/conf.d/default.conf

    php-fpm:
        container_name: webshop_php-fpm
        restart: unless-stopped
        tty: true
        depends_on:
            - nginx

        ports:
            - "9000:80"

        build:
            context: .
            dockerfile: PHP.Dockerfile

        volumes:
            - ../app:/app

nginx.config

server {
    # Port 80 default, port 443 for ssl
    listen 80 default_server;

    # Root directory
    root /app;
    index index.php;

    # Redirect non-existing urls
    location / {
        try_files uriuri/ /index.php?args;     }      # Handle php files     location ~ .php {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME document_rootfastcgi_script_name;
        fastcgi_pass php-fpm:9000;
    }
}

PHP.Dockerfile

FROM php:8.0.5-fpm

RUN docker-php-ext-install pdo pdo_mysql

EXPOSE 9000
Anonymous Asked question May 13, 2021