How do I implement MailCatcher under the docker-compose way?

The app in question is at https://github.com/jhsu802701/railn-20200316-215223-398 . Note that config/environments/development.rb is configured for MailCatcher.

I’ve been able to use MailCatcher without docker-compose, but I can’t quite figure out how to get it to work in a Rails app that revolves around docker-compose.

One solution I tried is to add the 1080:1080 port assignments to the web section of docker-compose.yml, but the MailCatcher interface doesn’t appear at http://localhost:1080/.

Another solution I’ve tried is to add a mailcatcher section under services to make use of a Docker image dedicated to MailCatcher. While the MailCatcher interface does appear, the email messages I expect when I try to sign up in my local setup do not materialize.

Exactly what am I missing?

Can you post your current docker compose file? Rails is also going to need to have permission to deliver mail to the composed container so you need to wire port 25 up.

You basically need to compose a dedicated container for mailcatcher.

I figured how what to do. Two things are needed:

  1. The mailcatcher service needs to be specified in the docker-compose.yml file. It should look something like this:
  web:

  ...

    links:
      - mailcatcher

   ...

  mailcatcher:
    image: yappabe/mailcatcher
    ports:
      - "1025:1025"
      - "1080:1080"

  ...

2, In the config/environments/development.rb file, the mailcatcher parameters need to be defined. The file should look something like this:

Rails.application.configure do
  ...
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = { address: 'mailcatcher', port: 1025 }
 ...
end

Yes, that address in config/environments/development.rb needs to be "mailcatcher".  Things didn't work when I used "localhost".

All this has been incorporated into seciton 04-03 of my new Rails Neutrino tool at GitHub - rubyonracetracks/rails_neutrino_5.

1 Like