![](/img/trans.png)
[英]Redis/Resque [Error connecting to Redis on localhost:6379 (ECONNREFUSED)]
[英]Using Resque-Scheduler with Docker-Compose - Error connecting to Redis on localhost:6379
我正在尝试运行我的Rails应用程序,resque和Redis。 使用工头等我的设置可以正常工作,但是当我尝试使用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)
我的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
我的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
我的procfile:
web: bundle exec puma -C config/puma.rb
resque: bundle exec rake resque:work QUEUE=*
scheduler: bundle exec rake resque:scheduler
我的配置/初始化/ resque.rb
redis_url = ENV["REDIS_URL"] || "redis://localhost:6379"
Redis.current = Redis.new(url: redis_url)
Resque.redis = Redis.current
和我的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
该问题似乎是Resque-Scheduler特有的。 如果将其从procfile中删除,则可以使用Docker-Compose启动我的应用程序,并且可以看到执行resque作业并看到它们正在运行。
但是,在手动或与领班(不使用容器)一起启动时,调度程序可以很好地工作,因此我希望也可以在这里使用它。
从我的头顶上看到一些东西:
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
最终从这里得到这个答案的线索: Docker-compose-Redis的值为0.0.0.0而不是127.0.0.1
似乎我需要在设置任务以及初始化程序中设置我的Resque redis连接。 最后,将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.