serversideup / docker-php

🐳 Production-ready Docker images for PHP. Optimized for Laravel, WordPress, and more!
https://serversideup.net/open-source/docker-php/
GNU General Public License v3.0
1.74k stars 119 forks source link

cannot create /etc/unit/config.d/config.json: Permission denied #318

Closed Jackardios closed 6 months ago

Jackardios commented 6 months ago

Affected Docker Images

serversideup/php:beta-8.3-unit

Docker Labels of the affected images

No response

Current Behavior

after updating https://github.com/serversideup/docker-php/pull/311 an error appeared when starting the container:

/usr/local/bin/docker-php-serversideup-entrypoint: 57: /etc/entrypoint.d/10-init-unit.sh: cannot create /etc/unit/config.d/config.json: Permission denied
nit-unit: Processing /etc/unit/config.d/ssl-off.json.template → /etc/unit/config.d/config.json...
Снимок экрана 2024-04-23 в 00 14 08

Expected Behavior

The container should start without errors

Steps To Reproduce

  1. dockerfile:
    
    # ======================================================================================================================
    #                                                   --- Base ---
    # ---------------  This stage install needed extenstions, plugins and add all needed configurations  -------------------
    # ======================================================================================================================

FROM serversideup/php:beta-8.3-unit as base

USER root

Install dependencies needed inside base image

RUN apt-get update && apt-get install -y \ curl \ vim \ git \ wget \ zsh \ default-mysql-client \ && rm -rf /var/lib/apt/lists/*

Install and enable PHP extensions

RUN install-php-extensions \ apcu \ bcmath \ ctype \ curl \ exif \ gd \ imagick/imagick@master \ intl \ mbstring \ opcache \ pcntl \ pdo_mysql \ redis \ zip

Fix permission issues in development by setting the "www-data"

user to the same user and group that is running docker.

ARG USER_ID ARG GROUP_ID RUN docker-php-serversideup-set-id www-data ${USER_ID}:${GROUP_ID}

USER www-data

======================================================================================================================

--- Development ---

======================================================================================================================

FROM base as development

COPY ./docker/php/config/php-config.base.ini /usr/local/etc/php/conf.d/php-config.base.ini COPY ./docker/php/config/php-config.development.ini /usr/local/etc/php/conf.d/php-config.development.ini

WORKDIR /var/www/html

======================================================================================================================

--- Production ---

======================================================================================================================

FROM base as production

COPY ./docker/php/config/php-config.base.ini /usr/local/etc/php/conf.d/php-config.base.ini COPY ./docker/php/config/php-config.production.ini /usr/local/etc/php/conf.d/php-config.production.ini

WORKDIR /var/www/html

For security and isolation, instead of mounting the folder, we copy all files to the container

COPY --chown=www-data:www-data . /var/www/html

Run composer install

RUN VIEW_COMPILED_PATH=./ composer install --optimize-autoloader --apcu-autoloader --no-dev -n --no-progress && \ composer check-platform-reqs

2. service in docker-compose:
```yaml
services:
  php:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: development
      args:
        USER_ID: ${USER_ID}
        GROUP_ID: ${GROUP_ID}
    restart: unless-stopped
    working_dir: /var/www/html
    depends_on:
      - mysql-test
      - mysql
      - elasticsearch
      - redis
    volumes:
      - .:/var/www/html
      - ~/.composer:/home/composer/.cache/composer
      - ~/.composer/auth.json:/config/composer/auth.json
      - ./vendor:/var/www/html/vendor:delegated
  1. run docker compose
    USER_ID="$(id -u)" GROUP_ID="$(id -g)" docker compose up --build -d

Host Operating System

MacOS 14.3.1

Docker Version

24.0.6

Anything else?

No response

jaydrogers commented 6 months ago

Be sure you're calling docker-php-serversideup-set-file-permissions when you're changing the user: https://serversideup.net/open-source/docker-php/docs/reference/command-reference#docker-php-serversideup-set-file-permissions

See the examples here: https://serversideup.net/open-source/docker-php/docs/guide/understanding-file-permissions

I'll re-open this issue if you're not able to get it to work 👍

Jackardios commented 6 months ago

@jaydrogers Thank you very much! Adding the docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service unit command worked for me