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.
Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.
- 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
docker network create app-net
docker run -d --name=mailhog --restart=always --network=app-net \ -p 8080:1025 -p 8081:8025 \ mailhog/mailhog
To access web UI, open a web browser and go to
<IP_ADDRESS> is the IP address of the system.
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