Skip to content

Commit febcd50

Browse files
committed
feat: add Dockerfile for multi-stage build of Laravel application
1 parent 83ff8a7 commit febcd50

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Dockerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Multi-stage build for Laravel application
2+
FROM php:8.2-fpm-alpine as base
3+
4+
# Install system dependencies
5+
RUN apk add --no-cache \
6+
git \
7+
curl \
8+
libpng-dev \
9+
libxml2-dev \
10+
zip \
11+
unzip \
12+
oniguruma-dev \
13+
icu-dev \
14+
libzip-dev \
15+
freetype-dev \
16+
libjpeg-turbo-dev
17+
18+
# Install PHP extensions
19+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
20+
&& docker-php-ext-install \
21+
pdo_mysql \
22+
mbstring \
23+
exif \
24+
pcntl \
25+
bcmath \
26+
gd \
27+
intl \
28+
zip \
29+
opcache
30+
31+
# Install Composer
32+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
33+
34+
# Set working directory
35+
WORKDIR /var/www/html
36+
37+
# Copy composer files first for better caching
38+
COPY composer.json composer.lock ./
39+
40+
# Install PHP dependencies
41+
RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist
42+
43+
# Copy application files
44+
COPY . .
45+
46+
# Complete composer installation
47+
RUN composer dump-autoload --optimize
48+
49+
# Set permissions
50+
RUN chown -R www-data:www-data /var/www/html \
51+
&& chmod -R 755 /var/www/html/storage \
52+
&& chmod -R 755 /var/www/html/bootstrap/cache
53+
54+
# Production stage with nginx
55+
FROM nginx:alpine as production
56+
57+
# Copy nginx configuration
58+
COPY docker/nginx.conf /etc/nginx/nginx.conf
59+
60+
# Copy application from base stage
61+
COPY --from=base /var/www/html /var/www/html
62+
63+
# Expose port
64+
EXPOSE 80
65+
66+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)