[英]Using Resque-Scheduler with Docker-Compose - Error connecting to Redis on localhost:6379
I'm trying to run my rails app, resque and redis. 我正在尝试运行我的Rails应用程序,resque和Redis。 Using foreman etc my setup works fine but when I try to run it in Docker using docker-compose I get: 使用工头等我的设置可以正常工作,但是当我尝试使用docker-compose在Docker中运行它时,我得到了:
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: 我的Dockerfile看起来像:
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: 我的Docker Compose YML看起来像:
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: 我的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 我的配置/初始化/ 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 和我的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 UPDATE
The problem appears to be specifically with Resque-Scheduler. 该问题似乎是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. 如果将其从procfile中删除,则可以使用Docker-Compose启动我的应用程序,并且可以看到执行resque作业并看到它们正在运行。
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. 但是,在手动或与领班(不使用容器)一起启动时,调度程序可以很好地工作,因此我希望也可以在这里使用它。
From the top of my head a see few things: 从我的头顶上看到一些东西:
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 --> try better redis://cache
links:
- redis
redis:
image: redis:5.0.5-alpine
Got a clue from this answer here in the end: Docker-compose - Redis at 0.0.0.0 instead of 127.0.0.1 最终从这里得到这个答案的线索: Docker-compose-Redis的值为0.0.0.0而不是127.0.0.1
It seems I needed to set my Resque redis connection in the setup task as well as in the initializer. 似乎我需要在设置任务以及初始化程序中设置我的Resque redis连接。 Adding Resque.redis = Redis.current into my resque.rake setup task finally got it all working: 最后,将Resque.redis = Redis.current添加到我的resque.rake设置任务中,一切正常:
require "resque/tasks"
require "resque/scheduler/tasks"
task "resque:preload" => :environment
namespace :resque do
task :setup do
require "resque"
Resque.redis = Redis.current
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.