How to run a cron job inside a docker container?

前端 未结 20 1692
無奈伤痛
無奈伤痛 2020-11-22 05:36

I am trying to run a cronjob inside a docker container that invokes a shell script.

Yesterday I have been searching all over the web and stack overflow, but I could

20条回答
  •  爱一瞬间的悲伤
    2020-11-22 06:01

    Try using clockwork gem to schedule tasks. Follow the steps provided in this link.

    http://fuzzyblog.io/blog/rails/2017/05/11/adding-cron-to-a-dockerized-rails-application-using-clockwork.html

    You can call the rake task inside lib/clock.rb file as below.

    every(1.day, 'Import large data from csv files', :at => '5:00') do |job|
      `rake 'portal:import_data_from_csv'`
    end
    

    Create a separate container in docker-compose file & run the below command inside the container.

    command: bundle exec clockwork lib/clock.rb
    

提交回复
热议问题