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:

  • After installing docker on centos7,Failed to start docker.“Job for docker.service failed.”
  • How to get this to work? Dockerfile FROM {YourPrivateRepo.azurecr.io/some/repo}
  • Network configuration docker PHP API
  • Decrypt with gpg from inside a docker container
  • Kafka log directories in Docker
  • docker container ssl certificates
  • 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.

  • How to deploy docker file on other server
  • LDAP authentication in Docker container
  • how can i dynamically create a docker container from a node application
  • See full command of running/stopped container in Docker
  • Can I export a container with data and everything to spawn a complete copy on another computer?
  • Create shared package cache folder for a Docker container
  • 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.