Skip to content

Instantly share code, notes, and snippets.

@michaelbragg
Created July 18, 2020 06:08
Show Gist options
  • Save michaelbragg/13cde0a3b6ae4770bbd578a8db2b7918 to your computer and use it in GitHub Desktop.
Save michaelbragg/13cde0a3b6ae4770bbd578a8db2b7918 to your computer and use it in GitHub Desktop.
Docker | WordPress | Mailhog: Add the ability to send email from WordPress and have it caught in Mailhog.

Add the ability to send email from WordPress and have it caught in Mailhog.

Adding a custom dockerfile based on the official WordPress docker file with MSMTP install and configured.

This sets the default SMTP details for the server to those of MailHog.

volumes:
db_data:
version: '3.7'
services:
mysql:
container_name: mysql
image: mysql:5.7
volumes:
- ./db:/docker-entrypoint-initdb.d
- ./db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
container_name: wordpress
build:
dockerfile: ./wordpress.dockerfile
context: .
volumes:
- ./:/var/www/
- ./php.ini:/usr/local/etc/php/php.ini
depends_on:
- mysql
links:
- mysql:mysql
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
mailhog:
container_name: mailhog
image: mailhog/mailhog:latest
restart: always
ports:
- 1025:1025
- 8025:8025
volumes:
wordpress:
db_data:
# Set default values for all following accounts.
account default
host mailhog
port 1025
from webmaster@localhost
tls off
tls_starttls off
syslog LOG_MAIL
logfile /var/www/msmtp.log
sendmail_path = "/usr/bin/msmtp -t"
mail.log = "/var/www/phpmail.log"
FROM wordpress:latest
RUN apt-get update && apt-get install msmtp -y && \
rm -rf /var/lib/apt/lists/*
COPY msmtprc /etc/msmtprc
RUN chown :msmtp /etc/msmtprc && \
chmod 640 /etc/msmtprc
@juleedev
Copy link

juleedev commented Dec 7, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment