PHP-FPM 尝试创建目录时 Docker 撰写权限被拒绝

PHP-FPM 尝试创建目录时 Docker 撰写权限被拒绝

我有这个正在试验的docker-compose。我使用Nginx的fastCGI来运行脚本。

docker-compose.yml

version: "3"

  services:
    psqldb:
      build:
        context: .
        dockerfile: docker/psql/Dockerfile
        args:
          UID: "${UID}"
          GID: "${GID}"
      restart: always
      environment:
        POSTGRES_USER:  postgres
        POSTGRES_PASSWORD: d;%f=68ZXJENER-R
        PGDATA: /pg-data
      volumes:
        - ./docker/.data/pgsql/:/pg-data
        - ./docker/.log/pgsql/:/var/log/postgresql/
      ports:
        - "5432:5432"
    phpapp:
      build:
        context: ./
        dockerfile: docker/php-fpm/Dockerfile_dev
        args:
          UID: "${UID}"
          GID: "${GID}"
      restart: unless-stopped
      environment:
        DB_HOST: psqldb
        POSTGRES_PASSWORD: d;%f=68ZXJENER-R
        DEBUG_MODE: 1
      volumes:
        - ./docker/php-fpm/config/zzz-phpSettings.conf:/usr/local/etc/php-fpm.d/zzz-phpSettings.conf
        - ./docker/.log/phpfpm/:/var/log/
        - ./phpcode/:/var/www
      depends_on:
        - psqldb

PHP Dockerfile:

FROM php:8.0.9-fpm-alpine

ARG UID
ARG GID

RUN addgroup --gid GID docker
RUN adduser --disabled-password --gecos '' --uid $UID --gid $GID docker
USER docker

WORKDIR /var/www

RUN apk update \
RUN apk add \
    build-base \
    vim \
    tzdata

# set Timezone
ENV TZ=Europe/Prague

# FIX for PDO-PGSQL
RUN set -ex \
  && apk --no-cache add \
    postgresql-dev

RUN docker-php-ext-install pdo pdo_pgsql

EXPOSE 9000

问题是日志和数据的卷目录是在 ROOT 用户下创建的,而不是在指定用户下创建的。如何解决?我尝试了很多互联网技巧,这是我找到的最后一个,那么我怎样才能让它运行而不chowning一直运行呢?

相关内容