Laravel Dockerfile generator
Generate a production Dockerfile for Laravel on FrankenPHP — OPcache tuned, config and routes cached at build time, running as www-data.
Configure
Loading...
What this Dockerfile does
2 items need attention
Needs attention: Only public/ is web-reachable
If the document root points at the project root instead, your .env, composer.json and vendor tree all become downloadable. Double-check this field.
Needs attention: storage/ needs a volume
Logs, sessions, cached views and uploads are all written under storage/. Without a mounted volume they are lost when the container is replaced.
Good practice: Multi-stage build (3 stages)
Compilers, dev dependencies and source files stay in the build stages. Only the runtime artefacts are copied into the final image.
Good practice: Runs as www-data, not root
A container escape from a root process is a host root process. Dropping privileges is the cheapest hardening step there is.
Good practice: .dockerignore keeps secrets out of the build context
`.git`, `.env` and local dependency folders never reach the daemon, so they cannot end up in a layer or in `docker history`.
Good practice: Dependency cache persists across builds
BuildKit cache mounts keep the package manager store outside the image. Rebuilds after a lockfile change reuse everything already downloaded, and the cache adds nothing to the final size.
Good practice: Healthcheck defined
Docker, Compose and Easypanel can tell the difference between a running process and a working app, and restart it when it wedges.
Good practice: OPcache with timestamp validation off
The image is immutable, so PHP never needs to stat files to check for changes. This is usually a double-digit percentage win over the defaults.
Good practice: Class map authoritative autoloader
`composer dump-autoload --classmap-authoritative` resolves every class at build time, so there is no filesystem lookup on a cache miss at runtime.
Good practice: One process, HTTP/2 and HTTP/3
FrankenPHP embeds the PHP runtime inside Caddy, so there is no FPM pool to size and no second process to supervise. The old generator needed a third-party mega-image to get the same result.
Note: Requires BuildKit
BuildKit is the default builder in Docker 23 and later. On anything older, export `DOCKER_BUILDKIT=1` before building.
How to use it
Everything runs locally. Nothing is uploaded, and no account is needed.
Drop the files into your project root
Every generated file belongs next to your package manifest — the Dockerfile references paths relative to the build context, so nesting them in a subfolder breaks the COPY lines.
Build the image
docker build -t laravel .Run it
docker run --rm -p 8080:8080 laravelOr bring up the whole stack
docker compose up --build