If you're using Rails and you're implementing periodic processing, you'll probably mention whenever
.
Also, using Docker in a development environment has become commonplace these days. This time, I will summarize what you should be careful about when using whenever in such an environment.
There is no Rails code. It's about Docker settings.
Docker Ruby 2.6.3 Rails 5.2.3
Achieve periodic execution processing using whenever in Docker environment
It seems that cron is not installed in Docker by default, so install and start cron. Please refer to another article for how to start whenever.
Below are the settings.
Dockerfile
Dockerfile
FROM ruby:2.6.3 #version suits the environment
ENV LANG C.UTF-8
ENV TZ Asia/Tokyo
RUN apt-get update -qq && \
apt-get install -y build-essential \
libpq-dev \
nodejs \
npm \
vim \
default-mysql-client \
cron \ #← Installation
&& rm -rf /var/lib/apt/lists/*
RUN npm install n -g
RUN n 10.15.3
RUN service cron start #← Start cron
RUN gem install bundler -v 2.0.1
RUN gem install mysql2 -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
RUN mkdir /app
ENV APP_ROOT /app
ENV RAILS_ENV development
WORKDIR $APP_ROOT
ADD ./.git-credentials /root/.git-credentials
RUN git config --global credential.helper store
ADD ./app/Gemfile $APP_ROOT/
ADD ./app/Gemfile.lock $APP_ROOT/
RUN bundle install
ADD ./app/ $APP_ROOT/
Then build & up the container as usual.
Also, don't forget to check the startup with the following command.
$ service cron status
If it is running, you will see [ok] cron is running.
.
Now you can use whenever in the Docker environment. Regarding whenever, I think other people's articles are good, so please refer to that.
This person @ Esfahan's following article was very helpful. Configure cron with Rails whenever
Recommended Posts