【问题标题】:Sidekiq + redis + docker-compose + railsSidekiq + redis + docker-compose + rails
【发布时间】:2021-07-09 04:54:10
【问题描述】:

我将我的项目配置为使用列出的技术,但是在请求路由 http://localhost: 3000/sidekiq 时,它给出了错误 Error connected to Redis on 127.0.0.1:6379 (Errno :: ECONNREFUSED)。在docker运行的终端,可以看到如下内容:

#终端

redis_1    | 1:C 14 Apr 2021 04:55:29.294 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1    | 1:C 14 Apr 2021 04:55:29.294 # Redis version=5.0.12, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1    | 1:C 14 Apr 2021 04:55:29.294 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1    | 1:M 14 Apr 2021 04:55:29.297 * Running mode=standalone, port=6379.
redis_1    | 1:M 14 Apr 2021 04:55:29.297 # Server initialized
redis_1    | 1:M 14 Apr 2021 04:55:29.297 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1    | 1:M 14 Apr 2021 04:55:29.297 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1    | 1:M 14 Apr 2021 04:55:29.297 * DB loaded from disk: 0.000 seconds
redis_1    | 1:M 14 Apr 2021 04:55:29.297 * Ready to accept connections
sidekiq_1  | 2021-04-14T04:55:32.421Z pid=1 tid=4w5 INFO: Booting Sidekiq 6.2.1 with redis options {:url=>"redis://redis:6379/0"}
sidekiq_1  | 2021-04-14T04:55:32.547Z pid=1 tid=4w5 INFO: Booted Rails 6.1.3.1 application in development environment
sidekiq_1  | 2021-04-14T04:55:32.548Z pid=1 tid=4w5 INFO: Running in ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux]

#docker-compose.yml

version: "3.9"
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
  
  redis:
    image: 'redis:5-alpine'
    command: redis-server
    ports:
      - '6379:6379'

  sidekiq:
    depends_on:
      - 'redis'
    build: .
    command: bundle exec sidekiq
    volumes:
      - .:/myapp
    env_file:
    - .env
  
  web:
    depends_on:
      - 'db'
      - 'sidekiq'
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"

#Dockerfile

FROM ruby:2.7.3
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp


COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000


CMD ["rails", "server", "-b", "0.0.0.0"]

#routes.rb

require 'sidekiq/web'
Rails.application.routes.draw do
      
    
      
  mount Sidekiq::Web => '/sidekiq'
      
  ...other routes
end

#sidekiq.rb

sidekiq_config = { url: ENV['REDIS_URL'] }

Sidekiq.configure_server do |config|
  config.redis = sidekiq_config
end

Sidekiq.configure_client do |config|
  config.redis = sidekiq_config
end

#.env

REDIS_URL=redis://redis:6379/0

如果我遗漏了一些配置文件或者我的设置有什么问题,请告诉我?

【问题讨论】:

    标签: ruby-on-rails redis docker-compose sidekiq


    【解决方案1】:

    在我的情况下,原因是我忘了添加

    env_file:
    - .env
    

    在“web”部分的#docker-compose.yml 中。如果有人需要更多信息,我可以在这里回答:)

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 2019-03-03
      • 2016-03-16
      • 2019-11-04
      • 1970-01-01
      • 2019-02-05
      • 2018-06-26
      • 1970-01-01
      • 2016-04-16
      相关资源
      最近更新 更多