Files
nhgooi.nl/Dockerfile
T
eric.busandClaude Opus 5.5 da971e1646
Build and Deploy (dev) / build (push) Successful in 4m23s
docker: support running the container as www-data (uid 33)
- Set ownership of storage, bootstrap/cache and public/assets/vendor at
  build time
- Entrypoint only creates/chowns directories when running as root

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 14:17:42 +01:00

93 lines
2.5 KiB
Docker

FROM php:8.3.37-apache
# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs
RUN apt-get update && apt-get install -y \
git \
curl \
libicu-dev \
libzip-dev \
libonig-dev \
libssh2-1 \
libssh2-1-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pecl install ssh2 \
&& docker-php-ext-enable ssh2 \
&& docker-php-ext-configure intl \
&& docker-php-ext-install \
pdo \
pdo_mysql \
mysqli \
intl \
ftp \
mbstring \
bcmath \
zip
RUN a2enmod rewrite
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
WORKDIR /var/www/app
ENV APACHE_DOCUMENT_ROOT=/var/www/app/public
RUN sed -ri \
-e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' \
/etc/apache2/sites-available/*.conf \
/etc/apache2/apache2.conf \
/etc/apache2/conf-available/*.conf
RUN echo '<Directory /var/www/app/public>\n\
AllowOverride All\n\
Require all granted\n\
</Directory>' > /etc/apache2/conf-available/laravel.conf \
&& a2enconf laravel
# Install PHP dependencies first (cached layer, only rebuilt when composer files change).
# Scripts and autoloader are skipped here because the app code isn't copied yet.
COPY composer.json composer.lock ./
RUN composer install \
--no-dev \
--prefer-dist \
--no-interaction \
--no-scripts \
--no-autoloader
# Install npm dependencies (cached layer, only rebuilt when package.json/lock change).
# The postinstall script is skipped here; the assets are copied after the app code below.
COPY package.json package-lock.json ./
RUN npm ci --omit=dev --ignore-scripts
# Copy app files
COPY . .
# Create storage directories
RUN mkdir -p \
storage/app \
storage/framework/cache/data \
storage/framework/sessions \
storage/framework/views \
storage/logs \
bootstrap/cache \
public/assets/vendor
# Generate the optimized autoloader and run composer scripts (package:discover)
RUN composer dump-autoload --no-dev --optimize --no-interaction
# Copy the npm packages into public/assets/vendor, then make the directories
# Laravel writes to owned by www-data, so the container can run as uid 33
RUN node scripts/setup-vendor.js \
&& chown -R www-data:www-data storage bootstrap/cache public/assets/vendor \
&& chmod -R ug+rwX storage bootstrap/cache public/assets/vendor
# Copy and set up entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 80