-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (67 loc) · 2.31 KB
/
Copy pathDockerfile
File metadata and controls
84 lines (67 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# --- STAGE 1: PHP Base ---
# Here we prepare the base with PHP and all the necessary extensions.
FROM php:8.4-fpm-alpine AS base
LABEL maintainer="<demo@example.com>"
# Install system utilities and dependencies for PHP extensions
RUN apk add --no-cache \
$PHPIZE_DEPS \
libzip-dev \
postgresql-dev \
libpq \
oniguruma-dev \
libxml2-dev \
supervisor \
linux-headers \
nodejs \
yarn
# Install the PHP extensions required by your project
RUN docker-php-ext-install -j$(nproc) \
pcntl \
exif \
sockets \
pdo_pgsql \
zip \
mbstring \
bcmath \
dom \
xml
# Install Redis extension
RUN pecl install redis && docker-php-ext-enable redis
# Install Composer globally
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install RoadRunner for Octane
COPY --from=spiralscout/roadrunner:2025.1 /usr/bin/rr /usr/bin/rr
WORKDIR /app
# --- STAGE 2: Node.js Asset Builder ---
# A separate stage to install Node.js dependencies and cache them.
FROM node:22-alpine AS node_builder
# Set working directory inside the container
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# --- STAGE 3: Final Production Image ---
# Assemble everything into a clean and optimized image.
FROM base AS final
# Set production environment variables
ENV APP_ENV=production \
APP_DEBUG=false \
LOG_CHANNEL=stderr \
DB_CONNECTION=pgsql \
QUEUE_CONNECTION=redis \
SESSION_DRIVER=redis \
CACHE_STORE=redis
# Copy Composer files and install production dependencies
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-interaction --no-scripts --optimize-autoloader
# Copy the entire application code
COPY . .
# Copy node_modules from the builder stage and then build frontend assets.
# `yarn build` is run here because it requires PHP (for `artisan wayfinder:generate`).
COPY --from=node_builder /app/node_modules ./node_modules
RUN yarn build
# Set correct permissions for storage and cache directories
RUN chown -R www-data:www-data /app/storage /app/bootstrap/cache
# Expose the port that Octane will listen on
EXPOSE 8000
# The command to start Laravel Octane with RoadRunner. $PORT will be provided by the hosting service.
CMD ["php", "artisan", "octane:start", "--server=roadrunner", "--host=0.0.0.0", "--port=${PORT:-8000}"]