scho scho - 4 months ago 74
Ruby Question

How to put sidekiq into Docker in a rails application?

I am using rails, sidekiq and docker.

My docker-compose.yml file

sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
links:
- db
- redis


config/sidekiq.yml file

:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
- default


After I run
docker-compose up
, the sidekiq service can not start rightly.

sidekiq_1 | No such file or directory @ rb_sysopen - /testapp/tmp/pids/sidekiq.pid
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:365:in `initialize'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:365:in `open'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:365:in `write_pid'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:42:in `parse'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/bin/sidekiq:12:in `<top (required)>'
sidekiq_1 | /usr/local/bundle/bin/sidekiq:16:in `load'
sidekiq_1 | /usr/local/bundle/bin/sidekiq:16:in `<main>'
testapp_sidekiq_1 exited with code 1

Answer

Try to mount the volumes. Your docker-compose file should look like this (with PosgtreSQL as database) :

web:
  build: .
  volumes:
    - .:/myapp
  links:
    - db
    - redis
  ports:
    - "3000:3000"
  command: bundle exec rails server -b 0.0.0.0
sidekiq:
  build: .
  volumes:
    - .:/myapp
  links:
    - db
    - redis
  command: bundle exec sidekiq
db:
  image: postgres
redis:
  image: redis