简体   繁体   English

将Resque-Scheduler与Docker-Compose结合使用-在本地主机上连接到Redis时出错:6379

[英]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.

相关问题 Redis / Resque [在本地主机上连接到Redis时出错:6379(ECONNREFUSED)] - Redis/Resque [Error connecting to Redis on localhost:6379 (ECONNREFUSED)] Sidekiq 在 docker-compose 上的 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错 - Sidekiq Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) on docker-compose docker-compose 错误连接到 redis + sidekiq - docker-compose error connecting to redis + sidekiq (在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): 测试resque-scheduler - Testing resque-scheduler Rails-Redis :: CannotConnectError:在本地主机上连接Redis时出错:6379(Errno :: ECONNREFUSED) - Rails - Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) Redis :: CannotConnectError(在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): 使用Resque和Resque-scheduler在后台处理作业 - Processing jobs in the background using Resque and Resque-scheduler rails + docker + sidekiq +错误连接到127.0.0.1:6379上的Redis(Errno :: ECONNREFUSED) - rails + docker + sidekiq + Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) 在使用Resque-scheduler和redis时,在提到的延迟时间过后,延迟作业未进入主作业队列 - Delayed job not entering into the main jobs queue after the mentioned delayed time lapses while using Resque-scheduler and redis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM