DEV Community

Ibrar Hussain
Ibrar Hussain

Posted on

Setup Docker Container for MailHog to use it with Laravel app

If you have local setup via Homestead or Valet, you might need to use smtp setup for emails in your application. For local development, one of the choices is to use MailHog.

Setting up MailHog can be in many ways but in this article, we will talk about setting up docker container for it.

Following are the steps:

  • Install docker desktop

You can go to this link and choose the desired application for your operating system.

  • Create a folder called docker-workspace


mkdir docker-workspace


Enter fullscreen mode Exit fullscreen mode
  • Go to the folder and create a new file docker-compose.yml


cd docker-workspace
touch docker-compose.yml


Enter fullscreen mode Exit fullscreen mode
  • Open docker-compose.yml file and enter the following content:


version: "3.7"
services:

  # SMTP Server
  smtp:
    platform: linux/x86_64
    image: mailhog/mailhog
    container_name: docker-workspace-smtp
    logging:
      driver: 'none'
    ports:
      - "8003:1025"
      - "8100:8025"
    networks:
      - docker_workspace_network

networks:
  docker_workspace_network:
    driver: bridge


Enter fullscreen mode Exit fullscreen mode
  • Start the docker container via the following command:


docker-compose up -d


Enter fullscreen mode Exit fullscreen mode

MailHog app running

  • In your Laravel application change the .env to the following:


MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=8003
MAIL_USERNAME=''
MAIL_PASSWORD=''
MAIL_ENCRYPTION=null


Enter fullscreen mode Exit fullscreen mode
  • Now, sending emails from you app will start showing up in the MailHog

Happy Coding!

Top comments (0)