I have this docker-compose I'm experimenting with. Im using fastCGI from Nginx to run the script.
The 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
The 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
The problem is that the volume directories for log and data are created under ROOT user and not under the specified user.
How to solve that? I've tried many internet tips for this and this is the last I found, so how can I make it run without chowning
all the time?