Learning how to deploy Laravel with Docker in 2026 is the fastest way to eliminate the "works on my machine" headache that haunts PHP teams. Docker packages your Laravel app, its PHP version, Composer dependencies, Node assets, and web server into a single portable image that runs identically on a MacBook, a CI runner, or a Kubernetes cluster. This guide walks through the full workflow: building a multi-stage Dockerfile, orchestrating services with Docker Compose, pushing to a production registry, and picking the right platform for your scale.
Definition: Docker is a platform for packaging applications into lightweight, portable containers that run consistently across any environment. A Dockerfile is the recipe file that tells Docker how to build that container image.
Overview & Quick Answer
What the tutorial covers
This tutorial covers the complete production workflow: environment setup, a multi-stage Dockerfile for Laravel, Docker Compose for local development, image optimization, registry pushing, and platform selection for production. You will see real commands (multi-stage builds, `docker build`, `docker pull mariadb:11`) and a final persona table that maps reader roles to the right deployment strategy.
Direct answer: How to deploy Laravel with Docker
Here is the shortest correct path: write a multi-stage Dockerfile that installs Composer and Node in build stages, then copies the compiled `vendor/` folder and `public/js` / `public/css` assets into a slim PHP-FPM + nginx runtime image. Add a docker-compose.yml that wires app, MySQL, and Redis services. Push the image to a registry like Alibaba Cloud Container Registry or Docker Hub, then deploy to a managed Kubernetes service, a VPS, or a serverless platform like Vercel. The rest of this article expands every step with real tradeoffs.
Why Docker Matters for Laravel in 2026
Consistent environments across teams
Laravel pulls in PHP, Composer, Node, a database driver, a cache driver, and often Redis. Pinning all of those on every developer laptop and CI runner wastes hours. A pinned multi-stage Docker build reproduces the exact same stack every time, so a "SQLSTATE connection refused" on a teammate's machine never reaches a production deploy.
Scaling and micro-services trend
Modern Laravel stacks split workers, schedulers, and HTTP frontends into separate containers so each scales independently. The same Docker image can run as `app`, `queue`, or `scheduler` based on a `CONTAINER_ROLE` environment variable, which is exactly how Laravel News' queue and scheduler tutorial structures its Compose file.
Cost, vendor lock-in, and cloud-native integration
Docker is the lingua franca of every major cloud. The same image you build locally runs on Amazon EKS, Google GKE, Alibaba Cloud Container Service, or a Hostinger VPS without rewriting. For bursty traffic, Vercel Functions can even run your OCI image as a serverless function with Active CPU pricing tied to actual compute time, eliminating idle bills.
Prerequisites & Environment Setup
Required software: Docker Desktop, Composer, Node
You will need Docker Desktop (or Docker Engine on Linux), Composer 2.x, and Node 20 LTS with either NPM or Yarn. On a fresh Ubuntu 22.04 box, install Docker Engine and add your user to the `docker` group to avoid root-only commands. The Laravel CLI is optional but speeds up scaffolding via `laravel new multi-stage-demo`.
Project structure expectations
A standard Laravel 11 project ships with `composer.json`, `composer.lock`, `package.json`, a `public/` directory, and a `storage/` directory that needs write access. Your repository should include a `.dockerignore` and a `docker/` folder with the Dockerfile, an entrypoint script (`start.sh`), and an Apache or nginx vhost config (`vhost.conf`). The `laravel new docker-laravelcd` command from the Laravel News queue-and-scheduler walkthrough sets this up cleanly.
Environment variables & .env handling
Never commit a production `.env` to Git. Instead, ship a `.env.example` and inject real values through Docker Compose, a Kubernetes Secret, or a managed secret store. Variables like `APP_ENV=production`, `CACHE_DRIVER=redis`, `SESSION_DRIVER=redis`, `QUEUE_DRIVER=redis`, and `REDIS_HOST=redis` are set inside `docker-compose.yml` so the same image runs locally and in production with different configurations.
Building a Multi-Stage Dockerfile for Laravel
Stage 1: Install PHP, Composer, and system dependencies
The first stage uses a Composer image to resolve PHP dependencies without bloating the final image. A representative snippet looks like this:
FROM composer:2 as vendor
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --ignore-platform-reqs --no-interaction \
--no-plugins --no-scripts --prefer-dist
Using `COPY` instead of `ADD` is intentional. The Snyk guide on dockerizing PHP applications warns that `ADD` can pull from arbitrary URLs and increase the attack surface. Stick with `COPY` and a local `composer.lock`.
Stage 2: Copy application code and run Composer install
The second stage handles frontend assets with Node and Yarn:
FROM node:20-alpine as assets
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn production
Stage 3: Runtime image with PHP-FPM and nginx
The final stage starts from `php:8.0-fpm-alpine` (or the current LTS PHP 8.3-fpm-alpine) and only copies the artifacts produced by the two previous stages:
FROM php:8.3-fpm-alpine as runtime
WORKDIR /var/www/html
COPY --from=vendor /app/vendor ./vendor
COPY --from=assets /app/public/js ./public/js
COPY --from=assets /app/public/css ./public/css
COPY . .
RUN chown -R www-data:www-data storage bootstrap/cache
Handling public assets, storage, and permissions
Map a Docker volume to `storage/` and `bootstrap/cache/` so logs and cached views survive container restarts. Running as the `www-data` non-root user (as recommended in the Snyk hardening checklist) prevents privilege escalation if a PHP process is compromised.
Optimizing the Dockerfile: Caching & Asset Builds
Composer install cache strategy
Order matters. Copying `composer.json` and `composer.lock` first, then running `composer install`, lets Docker cache that layer. If only your application code changes, Composer never re-downloads anything and the build skips a 60-second dependency step.
Node/Yarn build cache to speed up assets
Same trick for Node: copy `package.json` and `yarn.lock` first, run `yarn install`, then copy the rest. A `.dockerignore` that excludes `.git`, `vendor`, `node_modules`, `public/js`, `public/css`, and `yarn-error.log` shrinks the build context sent to the Docker daemon and keeps caches warm across CI runs.
Reducing final image size with .dockerignore
Alpine-based PHP images can land under 200 MB if you avoid installing dev tools. The `laravel new multi-stage-demo` workflow from Laravel News' multi-stage demo shows a final image roughly 60% smaller than a naïve single-stage build.
Using php:8.0-fpm-alpine for lightweight runtime
Alpine's musl libc is the smallest reasonable choice for PHP-FPM. Confirm required PHP extensions (`pdo_mysql`, `redis`, `gd`, `intl`) are installed via `docker-php-ext-install` before the final `COPY`. Missing extensions are the number-one reason Laravel containers fail health checks on first boot.
Docker Compose for Local Development
Defining services: app, web, db, redis
A typical docker-compose.yml defines four services: `app` (PHP-FPM), `web` (nginx reverse proxy), `db` (`mysql:5.7` or `mariadb:11`), and `redis` (`redis:7-alpine`). The web service points to the `app` service over a private Docker network, which matches how Kubernetes services will resolve each other in production.
Volumes and bind mounts for code hot-reload
Mount the project root with `- .:/var/www/html` so file edits on the host appear instantly inside the container. Combined with Laravel's built-in dev server, you get immediate code changes without rebuilding. For databases, use a named volume (`mariadb_data`) so dropping the container does not delete your data. The Hostinger MariaDB guide walks through the exact `docker volume create mariadb_data` and `docker run -d --name mariadb-server -e MARIADB_ROOT_PASSWORD=...` commands.
Running artisan, queue workers, and scheduler
Add a `queue` service that runs `php artisan queue:work --tries=3` and a `scheduler` service running `php artisan schedule:work`. The trick used in the Laravel News scheduler walkthrough is a `start.sh` bash script that reads the `CONTAINER_ROLE` env variable and dispatches to the right command. One image, three roles.
Deploying to Production: Choosing a Platform
Kubernetes options: EKS, GKE, Alibaba Cloud Container Service
For high-traffic Laravel apps, a managed Kubernetes service is the gold standard. Alibaba Cloud Container Service is a strong pick for Asia-Pacific traffic, while GKE and EKS are better if you are already in those ecosystems. The full SitePoint walkthrough on Alibaba Cloud covers VPC creation, registry push, and cluster deploy step by step.
Serverless with Vercel Functions and OCI images
For marketing sites, dashboards, and small APIs, Vercel Functions can run a custom OCI image built from a `Dockerfile.vercel`. Vercel builds, stores, deploys, and scales based on traffic, with Active CPU pricing and automatic scale-to-zero after five minutes of idle time. The Cloud Native Now coverage notes that every `git push` triggers a fresh preview URL, similar to a frontend framework.
Docker Hub, Alibaba Cloud Container Registry, and CI/CD pipelines
Push your image to Docker Hub for public projects, or to a private registry like Alibaba Cloud Container Registry for enterprise workloads. A GitHub Actions workflow that runs `docker build`, scans with Snyk, and pushes on merge to `main` gives you reproducible, auditable deploys without managing a CI server.
Real-World Tradeoffs & Performance
Startup latency versus image size
Alpine images start in under two seconds on a warm cluster but can stall for 10+ seconds on a cold serverless node. If cold-start latency matters, switch to a `php:8.3-fpm` Debian-slim image at the cost of an extra 150 MB.
Complexity of multi-stage builds for simple apps
For a two-page brochure site, a multi-stage Dockerfile is overkill. A single `php:8.0-fpm-alpine` image with everything inlined builds faster and is easier for junior developers to read. The savings only kick in once your `vendor/` folder crosses 100 MB or you ship a frontend pipeline.
When a VM or shared hosting might be cheaper
A single 4 GB VPS running nginx + PHP-FPM + MariaDB costs a fraction of a managed Kubernetes cluster. If your traffic stays under 50k monthly visitors, the operational simplicity of a VPS (or Hostinger's Docker template) wins on cost. Containers become valuable the moment you have more than one service or more than one server.
Pros, Cons, and Best Practices
Security hardening: non-root users, secrets management
Run as `www-data`, never as root. Use Docker secrets or cloud secret managers instead of baking credentials into the image. Pin base image versions (e.g., `php:8.3-fpm-alpine3.19`) so a `latest` tag refresh cannot break your production deploy overnight.
CI/CD integration with GitHub Actions, GitLab CI, or Snyk
Add a Snyk scan step in CI to catch vulnerable base images before they reach production. GitHub Actions and GitLab CI both support cached Docker layers via `docker/build-push-action` and `kaniko`, which keeps pipelines under two minutes even for large Laravel apps.
Image versioning, tagging, and rollback strategy
Tag images with the Git SHA (`my-app:abc1234`) plus a moving `latest` tag. Rolling back is then a one-line `kubectl set image deployment/app app=my-app:previous-sha`. Mutable tags are fine for development; immutable SHA tags are mandatory for production audit trails.
Verdict: Multi-stage Docker builds with Docker Compose for local dev and a managed Kubernetes service or Vercel for production are the strongest default for any team shipping Laravel in 2026. Skip Docker only for tiny single-server sites where the operational overhead outweighs the reproducibility gains.
Common Mistakes & Troubleshooting
Permission errors on storage and logs
If `storage/logs/laravel.log` is missing or unwritable, the container has the wrong UID. Fix with `RUN chown -R www-data:www-data storage bootstrap/cache` in the runtime stage, then verify with `docker compose exec app ls -la storage`.
Cache misconfiguration causing stale dependencies
Switching branches and seeing the old `vendor/`? Your `.dockerignore` is missing `vendor`, so the build context overrides the cached Composer layer. Add `vendor`, `node_modules`, and `.git` to `.dockerignore` to let layer caching work as intended.
Missing .env files or wrong environment variables
Symptom: `APP_KEY` is missing or `DB_HOST` points to `localhost`. In Compose, set `DB_HOST=db` (the service name) instead of `127.0.0.1`. For production, mount the `.env` file as a Kubernetes Secret or pass it through your platform's env-var interface. Never commit it.
Who Should Use Docker for Laravel? (Personas Table)
| Target Persona | Recommended Option | Key Reason & Real-World Benefit |
|---|---|---|
| Solo developer on a small project | Docker Compose on a single Hostinger VPS | Cheap, fast to set up with Hostinger's Docker template, no cluster overhead |
| Team working on micro-services | Multi-stage Dockerfile + Kubernetes (EKS or GKE) | Independent scaling of web, queue, and scheduler containers |
| Enterprise with strict compliance needs | Private registry + Alibaba Cloud Container Service with RAM policies | Audit logs, RBAC, and network isolation meet most compliance frameworks |
| Serverless user leveraging Vercel Functions | Dockerfile.vercel with OCI image and Fluid compute | Zero ops, preview URLs per push, Active CPU pricing bills by real usage |