Skip to content

Instantly share code, notes, and snippets.

@JangoCG
Created September 26, 2025 22:32
Show Gist options
  • Select an option

  • Save JangoCG/3ed6468bd77beae4e488b8f3e6f0b07f to your computer and use it in GitHub Desktop.

Select an option

Save JangoCG/3ed6468bd77beae4e488b8f3e6f0b07f to your computer and use it in GitHub Desktop.
Laravel Inertia Dockerfile
############################################
# Base Image
############################################
# Learn more about the Server Side Up PHP Docker Images at:
# https://serversideup.net/open-source/docker-php/
FROM serversideup/php:8.3-fpm-nginx-alpine AS base
## Uncomment if you need to install additional PHP extensions
# USER root
# RUN install-php-extensions bcmath gd
############################################
# Development Image
############################################
FROM base AS development
# We can pass USER_ID and GROUP_ID as build arguments
# to ensure the www-data user has the same UID and GID
# as the user running Docker.
ARG USER_ID
ARG GROUP_ID
# Switch to root so we can set the user ID and group ID
USER root
# Set the user ID and group ID for www-data
RUN docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID && \
docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx
# Drop privileges back to www-data
USER www-data
############################################
# Asset Builder Image
############################################
FROM base AS assets
USER root
WORKDIR /var/www/html
RUN apk add --no-cache nodejs npm git
ENV PNPM_HOME="/root/.local/share/pnpm" \
PATH="/root/.local/share/pnpm:$PATH" \
NODE_ENV="production" \
COMPOSER_ALLOW_SUPERUSER=1
RUN npm install -g pnpm
ARG VITE_APP_NAME
ARG AUTORUN_ENABLED
ARG HEALTHCHECK_PATH
ARG SSL_MODE
ENV VITE_APP_NAME=${VITE_APP_NAME} \
AUTORUN_ENABLED=${AUTORUN_ENABLED} \
HEALTHCHECK_PATH=${HEALTHCHECK_PATH} \
SSL_MODE=${SSL_MODE}
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm run build
############################################
# CI image
############################################
FROM base AS ci
# Sometimes CI images need to run as root
# so we set the ROOT user and configure
# the PHP-FPM pool to run as www-data
USER root
RUN echo "user = www-data" >> /usr/local/etc/php-fpm.d/docker-php-serversideup-pool.conf && \
echo "group = www-data" >> /usr/local/etc/php-fpm.d/docker-php-serversideup-pool.conf
############################################
# Production Image
############################################
FROM base AS deploy
COPY --chown=www-data:www-data . /var/www/html
COPY --from=assets --chown=www-data:www-data /var/www/html/public/build /var/www/html/public/build
COPY --from=assets --chown=www-data:www-data /var/www/html/vendor /var/www/html/vendor
COPY --from=assets --chown=www-data:www-data /var/www/html/bootstrap/cache /var/www/html/bootstrap/cache
# Remove any Vite dev server hot file before shipping the image
RUN mkdir -p /var/www/html/dbs && \
chown -R www-data:www-data /var/www/html/dbs
USER www-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment