From a66a2a421fb9713a7fee02aa8ee85c73b05eabdc Mon Sep 17 00:00:00 2001 From: Cyril Chapellier Date: Mon, 26 Feb 2024 21:09:44 +0100 Subject: [PATCH] [Chore] Allow setting the uid/gid of the FPM image (#145) --- README.md | 11 ++++++++++- docker/Dockerfile | 9 ++++++++- docker/docker-compose.yml | 4 +++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index feee68c..516eb1c 100644 --- a/README.md +++ b/README.md @@ -325,7 +325,16 @@ A `Dockerfile` is available for you to compile the image. To build the checked out version, just run: - docker build --pull --file docker/Dockerfile --tag davis:latest . + docker build --pull --file docker/Dockerfile --tag davis:latest --build-arg fpm_user=82:82 . + +> [!TIP] +> +> The `fpm_user` build arg allows to set: +> - the uid FPM will run with +> - the owner of the app folder +> +> This is helpful if you have a proxy that does not use the same default PHP Alpine uid/gid for www-data (82:82). For instance, in the docker compose file, nginx uses 101:101 +> This will build a `davis:latest` image that you can directly use. Do not forget to pass sensible environment variables to the container since the _dist_ `.env` file will take precedence if no `.env.local` or environment variable is found. diff --git a/docker/Dockerfile b/docker/Dockerfile index ee7dcd8..dd7784e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,9 @@ FROM php:8.2-fpm-alpine +# https://github.com/docker-library/php/blob/master/8.2/alpine3.18/fpm/Dockerfile#L33 +ARG fpm_user=82:82 +ENV FPM_USER=${fpm_user} + LABEL org.opencontainers.image.authors="tchap@tchap.me" LABEL org.opencontainers.image.url="https://github.com/tchapi/davis/pkgs/container/davis" LABEL org.opencontainers.image.description="A simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 4" @@ -77,6 +81,9 @@ RUN curl https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/v0.5.0 RUN docker-php-source delete RUN rm -rf /usr/local/bin/composer -RUN chown -R www-data:www-data var +# Sets the app folder owner as the FPM user +RUN chown -R ${FPM_USER} . + +USER $FPM_USER HEALTHCHECK --interval=30s --timeout=1s CMD php-fpm-healthcheck || exit 1 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 27c9010..7c9ddc2 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,7 +4,7 @@ name: "davis-docker" services: nginx: - image: nginx:1.23-alpine + image: nginx:1.25-alpine container_name: nginx command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" depends_on: @@ -32,6 +32,8 @@ services: build: context: ../ dockerfile: ./docker/Dockerfile + args: + fpm_user: 101:101 image: davis:latest # If you want to use a prebuilt image from Github # image: ghcr.io/tchapi/davis:edge