Docker connect Mail catcher with WordPress

I want to set a sendmail_path in WordPress’ container and use a sendmail provided by another container. In my case its MailHog.

So this is my docker-compose:

  • Netcating from client to server with docker-ed application lags initially
  • how process static file when deploying django using docker and aws eb
  • libicui18n.so.52: cannot open shared object file
  • Error in docker container bash: vi: command not found
  • Centos cgconfig fails to start
  • Docker swarm - add new worker - re scale the service
  • version: '2'
    services:
        wordpress:
            image: wordpress
            links:
                - db:mysql
                - mailhog
            ports:
                - 80:80
            domainname: foo.com
            hostname: foo
            volumes:
                - ./public:/var/www/html
            environment:
                WORDPRESS_DB_PASSWORD: example
            depends_on:
               - mailhog
    
        mailhog:
            image: mailhog/mailhog
            ports:
                - 1025:1025
                - 8025:8025
    
        db:
            image: mariadb
            environment:
                MYSQL_ROOT_PASSWORD: example
    

    I tried executing the command: "echo 'sendmail_path = \"/usr/local/bin/mailhog sendmail\"' > /usr/local/etc/php/conf.d/mail.ini" on WordPress container but it actually prints it…

    Does these two have to share the volumes?

    PS. I know I can use it as a SMTP server in the APP but I want to deal with it in more automated way.

  • Can I clean /var/lib/docker/tmp?
  • Docker Expose ports dynamically
  • Kitematic docker config yml
  • Terminal with Docker Compose with Links
  • wildfly docker image authentication issue
  • docker compose file is invalid ,additional properties not allowed tty
  • One Solution collect form web for “Docker connect Mail catcher with WordPress”

    You don’t have mailhog installed in the wordpress container, the path /usr/local/bin/mailhog doesn’t exit.

    What you want to do is sending mail via sendmail and this mail must be catched by mailhog. To do this you must extend the wordpress dockerfile :

    FROM wordpress
    RUN curl --location --output /usr/local/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 && \
        chmod +x /usr/local/bin/mhsendmail
    
    RUN echo 'sendmail_path="/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025 --from=no-reply@docker.dev"' > /usr/local/etc/php/conf.d/mailhog.ini
    

    Note the --smtp-adrr parameter : it must be in the form <mailhog_hostname>:<mailhog_port>.

    Change your docker-compose.yml to build your dockerfile.

    version: '2'
    services:
        wordpress:
            build:
                context: ./
                dockerfile: ./Dockerfile
            links:
                - db:mysql
                - mailhog
            ports:
                - 80:80
            domainname: foo.com
            hostname: foo
            volumes:
                - ./public:/var/www/html
            environment:
                WORDPRESS_DB_PASSWORD: example
            depends_on:
               - mailhog
    
        mailhog:
            image: mailhog/mailhog
            ports:
                - 1025:1025
                - 8025:8025
    
        db:
            image: mariadb
            environment:
                MYSQL_ROOT_PASSWORD: example
    

    In this exemple, the dockerfile you have written must be named “Dockerfile” and must be in the current directory (where you run docker-compose). You can change the path accordingly. You can remove the 1025:1025 ports entry if you don’t need to connect to it from the host.

    Now the function mail() should work as intended.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.