refactor: переработка Docker-окружения Laravel

This commit is contained in:
2025-12-10 19:37:35 +03:00
parent 49b7d83dfa
commit 9315b97c66
12 changed files with 217 additions and 146 deletions

View File

@@ -1,23 +1,36 @@
ARG PHP_VERSION=8.3-fpm
FROM php:${PHP_VERSION}
FROM php:8.3-fpm
RUN apt-get update && apt-get install -y --no-install-recommends \
libpng-dev libonig-dev libxml2-dev libzip-dev \
zip unzip git \
zip unzip git gosu \
netcat-traditional \
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY --chown=www-data:www-data ./docker/docker-entrypoint.sh /usr/local/bin/
COPY ./docker/php-fpm.conf /usr/local/etc/php-fpm.d/zz-docker.conf
ARG UID
ARG GID
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create a new user with the specified UID and GID, reusing an existing group if GID exists
# and update php-fpm to use the new user and group
RUN if getent group ${GID}; then \
group_name=$(getent group ${GID} | cut -d: -f1); \
useradd -m -u ${UID} -g ${GID} -s /bin/bash www; \
else \
groupadd -g ${GID} www && \
useradd -m -u ${UID} -g www -s /bin/bash www; \
group_name=www; \
fi
# Update php-fpm to use the new user and group
RUN sed -i "s/user = www-data/user = www/g" /usr/local/etc/php-fpm.d/www.conf && \
sed -i "s/group = www-data/group = $group_name/g" /usr/local/etc/php-fpm.d/www.conf
COPY ./docker/entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
USER www-data
WORKDIR /var/www
EXPOSE 9000
ENTRYPOINT ["docker-entrypoint.sh"]
ENTRYPOINT ["entrypoint.sh"]
CMD ["php-fpm"]