Laravel Dockerfile generator

Get a multi-stage Dockerfile, a compose.yaml and the nginx config for a Laravel 13 app. Choose PHP-FPM with nginx, or FrankenPHP with Octane, and add a database, Redis, a queue worker and a scheduler.

Runtime
Needs laravel/octane in your app: composer require laravel/octane, then php artisan octane:install --server=frankenphp.
Each choice follows that branch's newest patch release.
Services
Build
The database, Redis, pcntl, bcmath, intl, zip and opcache extensions are added for you.
Dockerfile

To run it

    How the image is put together

    • Assets are built in their own stage. Node and node_modules are used to run Vite and then left behind. Only public/build reaches the final image.
    • Dependencies install before the code is copied. Docker reuses that layer until composer.json or composer.lock changes, so most rebuilds skip the Composer download.
    • Extensions come from install-php-extensions. It installs the system libraries each extension needs and removes the build tools afterwards. The official PHP image documentation points to it.
    • PHP-FPM runs as www-data. The process that executes your code is not root inside the container.
    • Secrets stay out of the image. .dockerignore excludes .env, and Compose passes it in when the container starts.

    Staying on patched images

    The image tags name a branch, such as php:8.5-fpm-alpine, and each one points at the newest patch release of that branch. A security fix reaches you without editing the Dockerfile, on one condition: Docker has to download it. By default a build reuses the base image already on the machine, however old.

    • The Compose file sets pull: true on every build and pull_policy: always on the database and Redis, so each build checks for newer images.
    • Rebuild and redeploy after a PHP security release. A running container keeps the PHP version it was built with.
    • To see what you are running: docker compose exec app php -v.
    • In CI, build with docker build --pull for the same effect.

    Two ways to serve PHP

    PHP-FPM with nginx is the classic pair. Nginx serves files from public/ and hands PHP requests to the app container. Every request starts from a clean state, which is the most forgiving setup.

    FrankenPHP with Octane is one container. The app boots once and stays in memory, which is faster. In return your code must not keep per-request state in static properties or singletons. The Dockerfile follows the one in the Laravel Octane documentation.

    Before real traffic

    • Run migrations as a release step, once per deploy: docker compose run --rm app php artisan migrate --force.
    • Cache the configuration when the container starts, after the environment is available: php artisan optimize. Caching it during the build would bake in an empty environment.
    • Sessions, cache, uploads and the SQLite file must live outside the container: in the database, Redis, object storage or a named volume. A container's own disk is discarded on every deploy.
    • Put TLS in front, with a load balancer, a reverse proxy or your host's ingress. With a proxy in front, configure Laravel's trusted proxies so it generates https links.
    • The scheduler container runs schedule:work, which stays in the foreground. On a normal server Laravel recommends cron with schedule:run. Run one scheduler only, however many app containers you scale to.

    Sources: Laravel 13 documentation for deployment, Octane with FrankenPHP and queues, the official PHP image, and the Docker build best practices.

    Building a SaaS on Laravel? Start with the foundation already built.

    Stack Toast is a Laravel 13 starter kit with authentication, billing through four payment processors, teams and a complete admin panel. Choose Livewire, React, Vue or API.

    • From $199, one payment
    • Full GitHub source
    • Unlimited projects
    • 30-day money-back guarantee
    The Stack Toast admin dashboard with revenue and subscription metrics