Home / Configs / Containers / Docker Compose for Mailpit

Docker Compose for Mailpit: catch test emails on localhost

Run a fake mail server on your computer, so test emails from your app show up in a web page instead of being sent.

For Docker with the Compose plugin (Docker Desktop, or Docker Engine 20.10 or newer).

Mailpit catches every email your app sends during development and shows it in a web inbox, so nothing reaches real people. Save this file, run one command, and point your app's mail settings at port 1025.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

You open this in your browser
Your app sends mail to this port

docker-compose.yml
services:
  mailpit:
    image: axllent/mailpit
    container_name: mailpit
    restart: unless-stopped
    ports:
      - "8025:8025"
      - "1025:1025"

How this setup works

Diagram: Your app, then Mailpit, then Web inbox
Your app (sends an email) → Mailpit (catches it on the SMTP port) → Web inbox (read it in a browser)

Step-by-step setup

  1. Save the file above as docker-compose.yml.
  2. Start it: docker compose up -d.
  3. Open http://localhost:8025 to see the empty inbox.
  4. In your app set the mail host to localhost, the port to 1025, and leave the username, password and encryption empty.
  5. Send a test email from your app. It appears in the inbox within a second.

What the important lines mean

Common errors and how to fix them

Bind for 0.0.0.0 failed: port is already allocated
Another program uses that port, such as an older mail tool. Change the left number of the port line, or stop the other program.
Connection refused on the SMTP port
The container is not running, or your app runs inside another container where localhost is itself. Use the service name mailpit as the host when both are in the same Compose file.
Emails do not appear in the inbox
Your app is not using SMTP, or its mail setting points elsewhere. Check the host and port, and turn encryption and authentication off.
SSL or TLS error from the app
Mailpit accepts plain SMTP by default. Set the encryption option in your app to none.

Frequently asked questions

Is Mailpit safe to use?
Yes for development. It never sends mail onward, so test emails cannot reach real addresses. Do not expose its ports to the internet.
What are the usual app settings?
Host localhost, port 1025, no username, no password, no encryption. In Laravel set MAIL_HOST and MAIL_PORT. In WordPress use an SMTP plugin with the same values.
Is this the same as MailHog?
They do the same job and use the same ports. Mailpit is actively developed, while MailHog has not had updates for years.

Written for: Docker Compose v2 · Updated 2026-10-11

Free tools that help

Fix a problem with this setup

More container configs

See all 41 config generators