← Customise this setup

Docker Compose for Laravel + Elasticsearch + Mailpit

Stack
PHP-FPM + Nginx + Elasticsearch + Mailpit

Laravel is the most popular PHP framework for web development, known for its elegant syntax and rich ecosystem. It is the framework of choice for SaaS products, REST APIs, and rapid application development with Eloquent ORM and first-class queue support.

This configuration has no database service. Add one with the generator above if your application needs to persist data — or keep it out if you're only prototyping stateless logic or a static/API-less layer.

Elasticsearch provides distributed full-text search and real-time analytics. It requires at least 1 GB of dedicated memory — ensure your Docker host has sufficient RAM before starting the stack.

When should you use this stack?

Laravel and Elasticsearch is a solid default for local development when your production environment matches it. If you're evaluating alternatives, the related configurations below swap one piece at a time — same framework with a different database, or the same data layer under a different framework — so you can compare without starting from scratch.

Quick start
Start stack docker compose up -d
Web http://localhost:8080
Mailpit UI http://localhost:8025

compose.yml

compose.yml
services:
  nginx:
    image: nginx:latest
    ports:
      - "${WEB_PORT-8080}:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - php

  php:
    image: php:8.5-fpm
    volumes:
      - .:/var/www/html

  elasticsearch:
    image: elasticsearch:8.11.0
    environment:
      discovery.type: single-node
      xpack.security.enabled: "false"
      ES_JAVA_OPTS: "-Xms512m -Xmx512m"
    ports:
      - "${ELASTICSEARCH_PORT-9200}:9200"
    volumes:
      - elasticsearch_data:/usr/share/elasticsearch/data
    healthcheck:
      test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -q status"]
      interval: 30s
      timeout: 10s
      retries: 5

  mailpit:
    image: axllent/mailpit
    ports:
      - "${MAILPIT_SMTP_PORT-1025}:1025"
      - "${MAILPIT_UI_PORT-8025}:8025"

volumes:
  elasticsearch_data:

docker/nginx/default.conf

Run mkdir -p docker/nginx first

docker/nginx/default.conf
server {
    listen 80;
    server_name localhost;

    root /var/www/html/public;
    index index.php index.html;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ \.php$ {
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

.env.example

Optional — Compose uses ${VAR-default} fallbacks

.env.example
WEB_PORT=8080

ELASTICSEARCH_PORT=9200

MAILPIT_SMTP_PORT=1025
MAILPIT_UI_PORT=8025

Frequently asked questions

How do I start this Laravel stack?
Download the files, run `docker compose up -d` from the project root, then open http://localhost:8080 in your browser. The web port is configurable via the `WEB_PORT` variable in `.env`.
Which PHP version does this configuration use?
This page uses PHP 8.5 by default. Use the generator above to pick 8.1 through 8.5 and regenerate the files with your chosen version.
What port does Elasticsearch run on?
Elasticsearch listens on port 9200 for HTTP requests. Check cluster health with `curl http://localhost:9200/_cluster/health`.
How do I view emails sent by the application?
Mailpit captures all outgoing mail and shows it in a web UI at http://localhost:8025. Point your app's SMTP settings at host `mailpit`, port 1025.
Is this configuration production-ready?
No — it is tuned for local development (bind-mounted source, default credentials, exposed ports). For production, remove the bind mounts, set real secrets, and add resource limits and restart policies.

Related configurations