Install MailHog Inside Docker Container in Linux

Install MailHog Inside Docker Container in Linux

MailHog is an email testing tool. It runs an SMTP server that catches emails sent to it. MailHog provides a web UI to view emails and a JSON API to retrieve them.

This tutorial explains how to install MailHog inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install MailHog

  • Host network

Run the following command to create a container for MailHog that uses host network:

docker run -d --name=mailhog --restart=always --network=host \
    mailhog/mailhog
  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, MailHog service is listening for SMTP connections on port 1025. Web UI is available on port 8025. Both ports can be changed with -p option.

docker network create app-net
docker run -d --name=mailhog --restart=always --network=app-net \
    -p 8080:1025 -p 8081:8025 \
    mailhog/mailhog

Testing MailHog

To access web UI, open a web browser and go to http://<IP_ADDRESS>:8025, where <IP_ADDRESS> is the IP address of the system.

MailHog Inside Docker Container in Linux

Uninstall MailHog

To completely remove MailHog, remove its container:

docker rm --force mailhog

Remove MailHog image:

docker rmi mailhog/mailhog

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.