I'm trying to run my rails app, resque and redis. Using foreman etc my setup works fine but when I try to run it in Docker using docker-compose I get:
app_1 | 21:03:13 resque.1 | Redis::CannotConnectError: Error connecting to Redis on redis://redis:6379 (SocketError)
app_1 | 21:03:13 resque.1 | Original Exception (Redis::CannotConnectError): Error connecting to Redis on redis://redis:6379 (SocketError)
My Dockerfile looks like:
FROM ruby:2.6.3-alpine
RUN apk update && apk add bash build-base libxml2-dev libxslt-dev postgresql postgresql-dev
VOLUME ["/code"]
WORKDIR /code
My Docker Compose YML looks like:
version: '3'
services:
app:
build: .
command:
- /bin/bash
- -c
- |
bundle check || bundle install
bundle exec rake db:migrate; rake db:seed
bundle exec foreman start
volumes:
- ./:/code
ports:
- "5000:5000"
depends_on:
- redis
environment:
REDIS_URL: redis://redis/5
redis:
image: redis:5.0.5-alpine
My procfile:
web: bundle exec puma -C config/puma.rb
resque: bundle exec rake resque:work QUEUE=*
scheduler: bundle exec rake resque:scheduler
my config/initializers/resque.rb
redis_url = ENV["REDIS_URL"] || "redis://localhost:6379"
Redis.current = Redis.new(url: redis_url)
Resque.redis = Redis.current
and my lib/tasks/resque.rake
require "resque/tasks"
require "resque/scheduler/tasks"
task "resque:preload" => :environment
namespace :resque do
task :setup do
require "resque"
end
task setup_schedule: :setup do
require "resque-scheduler"
Resque.schedule = YAML.load_file(Rails.root.join("config","schedule.yml"))
end
task scheduler: :setup_schedule
end
UPDATE
The problem appears to be specifically with Resque-Scheduler. If I remove that from my procfile I can start my app fine with Docker-Compose and I can see perform resque jobs and see them running.
However the scheduler works fine when started with manually or with foreman (not using containers) so I'd like to be able to get it working here also.