Reputation: 1117
I have shifted my rails application to docker. Everything is working fine except the rails delayed_job. I have use delayed_job to send email. I have started my job through command docker-compose run web rake jobs:work
it has started succesfully as shown in the image.
Now when I am trying to send email in console it is showing that the email is initiated as shown in the above image.
Do I have to include any line in my docker-compose.yml or Dockerfile.
My Dockerfile is :
FROM ruby:2.3.6
RUN mkdir -p /railsapp
WORKDIR /railsapp
RUN apt-get update && apt-get install -y nodejs --no-install-recommends
RUN apt-get update && apt-get install -y mysql-client --no-install-recommends
COPY Gemfile /railsapp/
COPY Gemfile.lock /railsapp/
RUN bundle install
COPY . /railsapp
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
My docker-compose.yml is :
version: '3.3'
services:
mysql:
image: mysql
restart: always
ports:
- "3002:3002"
volumes:
- /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=dev
web:
build: .
environment:
- RAILS_ENV=development
ports:
- '3000:3000'
volumes:
- .:/railsapp
links:
- "mysql"
depends_on:
- mysql
I am completely new to docker.
Upvotes: 1
Views: 1327
Reputation: 6310
I am not sure how you have configured your ActionMailer, but if you are using default settings, you are probably sending e-mail via your servers built-in Mail Transfer Agent
. In practice, this means that Rails invokes a system command called sendmail
which accepts the outgoing e-mail and puts it in a local queue to be picked up by a service/daemon called postfix
. Unless you have explicitly enabled it, Postfix is not running inside your Docker container and your e-mails are not going anywhere.
You can see an example of sendmail
here: https://help.dreamhost.com/hc/en-us/articles/216687518-How-do-I-use-Sendmail-
You have two options.
1) Enable Postfix inside your Delayed Job container. This involves finding out which OS package to install and which daemon/service to run.
2) Switch to an external SaaS mailing service such as Sendgrid or Mailgun. These services expose REST or SOAP API's which ActionMailer can call directly to ship a particular e-mail. This eliminates the needs to host your own postfix server. In addition, these third party services are specialized in correct delivery, which reduces the risk of your e-mails inadvertedly going into the recipients spam folder. I recommend this approach.
Upvotes: 1