[Docker] Use whenever with Docker + Rails


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

Thing you want to do

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.



FROM ruby:2.6.3 #version suits the environment

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 RAILS_ENV development

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

[Docker] Use whenever with Docker + Rails
Run Rails whenever with docker
[Rails] How to use rails console with docker
Rails deploy with Docker
Use Puphpeteer with Docker
Use ngrok with Docker
Use GDAL with Python with Docker
[Docker] Rails 5.2 environment construction with docker
Use multiple databases with Rails 6.0
Rails + MySQL environment construction with Docker
Why use orchestration tools with Docker
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
[Environment construction with Docker] Rails 6 & MySQL 8
Use cuda11.0 with pytorch using Docker
Rails environment construction with Docker (personal apocalypse)
Building Rails 6 and PostgreSQL environment with Docker
Create Rails 6 + MySQL environment with Docker compose
Deploy to heroku with Docker (Rails 6, MySQL)
Use Symbolic Link with Docker multi-stage builds
Rails Docker ~ Part 1 ~
Rails Docker ~ Part 2 ~
[Rails] Use jQuery
Use ZStandard with .NET Core + Docker (Alpine)
How to build Rails 6 environment with Docker
Introducing Rspec with Ruby on Rails x Docker
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Notes on building Rails6 / PostgreSQL with Docker Compose
How to use docker compose with NVIDIA Jetson
Output simple graph with Rails Use gem-chartkick / groupdate
How to use nginx-ingress-controller with Docker for Mac
[Rails] How to build an environment with Docker
Easy to display hello world with Rails + Docker
Use ProGuard with Gradle
Rails Docker environment construction
Docker x Rails 6 (memo)
Launch MariaDB with Docker
Run Pico with docker
[Rails 6] RuntimeError with $ rails s
Explode Docker with WSL2
Why we use Docker
Use XVim2 with Xcode 12.0.1
Use CentOS with LXD
Handle devise with Rails
[Rails] Learning with Rails tutorial
Operate Emby with Docker
Try WildFly with Docker
[Rails] Test with RSpec
Run Payara with Docker
Use webmock with Rspec
Use images in Rails
[Docker] Connection with MySQL
Php settings with Docker
[Rails] Development with MySQL
Supports multilingualization with Rails!
Use jlink with gradle
Double polymorphic with Rails
Install Composer with Docker
Bundle install with docker + rails6 does not reflect gem
Error encountered with notes when deploying docker on rails
Build Rails (API) x MySQL x Nuxt.js environment with Docker