generated from theradcoza/Laravel-Docker-Dev-Template
84 lines
2.0 KiB
Docker
84 lines
2.0 KiB
Docker
FROM php:8.3-fpm
|
|
|
|
# Set working directory
|
|
WORKDIR /var/www/html
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
git \
|
|
curl \
|
|
libpng-dev \
|
|
libonig-dev \
|
|
libxml2-dev \
|
|
libzip-dev \
|
|
libpq-dev \
|
|
libicu-dev \
|
|
zip \
|
|
unzip \
|
|
supervisor \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install PHP extensions
|
|
RUN docker-php-ext-configure intl \
|
|
&& docker-php-ext-install \
|
|
pdo_mysql \
|
|
pdo_pgsql \
|
|
mbstring \
|
|
exif \
|
|
pcntl \
|
|
bcmath \
|
|
gd \
|
|
zip \
|
|
intl \
|
|
opcache
|
|
|
|
# Install Redis extension
|
|
RUN pecl install redis && docker-php-ext-enable redis
|
|
|
|
# Install Composer
|
|
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
|
|
|
# Install Node.js for asset building
|
|
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
|
&& apt-get install -y nodejs \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create system user to run Composer and Artisan commands
|
|
RUN useradd -G www-data,root -u 1000 -d /home/devuser devuser
|
|
RUN mkdir -p /home/devuser/.composer && \
|
|
chown -R devuser:devuser /home/devuser
|
|
|
|
# Copy composer files first
|
|
COPY --chown=devuser:devuser ./src/composer.json ./src/composer.lock /var/www/html/
|
|
|
|
# Install composer dependencies as devuser
|
|
USER devuser
|
|
RUN composer install --no-interaction --no-dev --optimize-autoloader --no-scripts
|
|
|
|
# Switch back to root to copy rest of files
|
|
USER root
|
|
|
|
# Copy existing application directory
|
|
COPY --chown=devuser:devuser ./src /var/www/html
|
|
|
|
# Set proper permissions
|
|
RUN chown -R devuser:www-data /var/www/html \
|
|
&& chmod -R 775 /var/www/html/storage 2>/dev/null || true \
|
|
&& chmod -R 775 /var/www/html/bootstrap/cache 2>/dev/null || true
|
|
|
|
# Build frontend assets (if package.json exists)
|
|
RUN if [ -f "package.json" ]; then \
|
|
npm ci --ignore-scripts && \
|
|
npm run build && \
|
|
rm -rf node_modules; \
|
|
fi
|
|
|
|
# Run post-install scripts
|
|
USER devuser
|
|
RUN composer run-script post-autoload-dump 2>/dev/null || true
|
|
|
|
USER devuser
|
|
|
|
EXPOSE 9000
|
|
CMD ["php-fpm"]
|