Last active
March 3, 2026 16:04
-
-
Save jswebschmiede/cf47af490d71b6f84c453b9ddbd3aca7 to your computer and use it in GitHub Desktop.
Create Docker Image from Laravel Sails for deploying on a VPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node_modules | |
| vendor | |
| public/build | |
| .git | |
| .env | |
| docker-compose.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Stage 1: PHP dependencies (Composer) | |
| FROM composer:2.7 AS vendor_builder | |
| WORKDIR /app | |
| COPY composer.json composer.lock ./ | |
| RUN composer install --no-dev --no-scripts --prefer-dist --optimize-autoloader --no-interaction --no-progress | |
| # Stage 2: Frontend assets (Vite) | |
| FROM node:20-alpine AS asset_builder | |
| WORKDIR /app | |
| COPY package.json package-lock.json vite.config.js tailwind.config.js postcss.config.js ./ | |
| COPY resources/ ./resources/ | |
| RUN npm ci && npm run build | |
| # Stage 3: Final production image | |
| FROM dunglas/frankenphp:1.3-php8.3-alpine | |
| WORKDIR /app | |
| # Install required PHP extensions for Laravel and MySQL | |
| RUN install-php-extensions \ | |
| pdo_mysql \ | |
| gd \ | |
| intl \ | |
| zip \ | |
| opcache | |
| # Copy source code | |
| COPY . . | |
| # Overlay build artifacts from previous stages | |
| COPY --from=vendor_builder /app/vendor ./vendor | |
| COPY --from=asset_builder /app/public/build ./public/build | |
| # Runtime defaults for production deployments | |
| ENV APP_ENV=production \ | |
| APP_DEBUG=false \ | |
| LOG_CHANNEL=stderr \ | |
| SERVER_NAME=:80 | |
| # Ensure full Laravel storage structure exists and is writable | |
| RUN mkdir -p \ | |
| storage/framework/cache/data \ | |
| storage/framework/sessions \ | |
| storage/framework/views \ | |
| storage/logs \ | |
| bootstrap/cache \ | |
| && chown -R www-data:www-data storage bootstrap/cache | |
| EXPOSE 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment