错误连接被拒绝:Docker Rails中的MailCatcher



我在Docker中运行Rails应用程序,我想集成mailcatcher进行开发。

docker compose.yml

version: '3'
services:
db:
image: postgres:alpine
restart: always
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "9000:5432"
app:
build: 
context: .
dockerfile: ./docker/app/DockerFile
restart: always
command: bash -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/vsapp-cms-backend
- bundle_path:/bundle
environment: 
- BUNDLE_PATH=/bundle/vendor
ports:
- "3002:3000"
depends_on:
- db
mailcatcher:
image: schickling/mailcatcher
ports:
- "1080:1080"
- "1025:1025"
volumes:
bundle_path:
postgres-data:

开发.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { 
address: '127.0.0.1',
port: 1025 
}

我可以看到邮件收集器也在http://localhost:1080上运行但是当我运行UserMailer.send_invite(user).deliver_now!

我得到

Errno::ECONNREFUSED: Connection refused - connect(2) for "127.0.0.1" port 1025

我通过将地址从development.rb更改为mailcatcher来发送它

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { 
address: 'mailcatcher',
port: 1025 
}

相关内容

  • 没有找到相关文章