Rails 5.2, Docker Compose, Sidekiq, Redis.
This is the docker-compose file:
version: '3.6'
services:
redis:
image: 'redis:4.0-alpine'
command: redis-server
ports:
- '6379:6379'
volumes:
- 'redis:/data'
sidekiq:
depends_on:
- 'redis'
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- './:/app'
env_file:
- '.env'
api:
build: .
volumes:
- './:/app'
working_dir: /app
command: puma
ports:
- 3000:3000
depends_on:
- db
- redis
environment:
DATABASE_URL: postgres://postgres@db
db:
image: postgres:10.3-alpine
volumes:
redis:
postgres:
It seems sidekiq cannot find my Rails app.
If I change sidekiq to start like this:
command: bundle exec sidekiq -C config/sidekiq.yml -r /app
then I get this error:
Spring was unable to find your config/application.rb file. Your project root was detected at /api, so spring looked for /api/config/application.rb but it doesn't exist. You can configure the root of your application by setting Spring.application_root in config/spring.rb.
If I instead add the working_dir
setting to sidekiq:
sidekiq:
depends_on:
- 'redis'
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- './:/app'
env_file:
- '.env'
working_dir:
- '/app'
then I get this error:
2019-05-27T20:27:59.770Z 1 TID-gr1e0d7n5 INFO: Booting Sidekiq 5.1.1 with redis options {:url=>"redis://redis:6379/0", :id=>"Sidekiq-server-PID-1"}
sidekiq_1 | could not connect to server: No such file or directory
sidekiq_1 | Is the server running locally and accepting
sidekiq_1 | connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
So how do I make sidekiq start correctly in its container?
I have seen these answers, which are similar but not this particular error: