I configured my project to work with the listed technologies, but when requesting the route http://localhost: 3000/sidekiq
, it gives the error Error connecting to Redis on 127.0.0.1:6379 (Errno :: ECONNREFUSED)
. In the terminal where docker is running, you can see the following:
#terminal
redis_1 | 1:C 14 Apr 2021 04:55:29.294 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Ooredis_1 | 1:C 14 Apr 2021 04:55:29.294 # Redis version=5.0.12, bits=64, commit=00000000, modified=0, pid=1, just startedredis_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.confredis_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 initializedredis_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 secondsredis_1 | 1:M 14 Apr 2021 04:55:29.297 * Ready to accept connectionssidekiq_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 environmentsidekiq_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.3RUN apt-get update -qq && apt-get install -y nodejs postgresql-clientWORKDIR /myappCOPY Gemfile /myapp/GemfileCOPY Gemfile.lock /myapp/Gemfile.lockRUN bundle installCOPY . /myappCOPY entrypoint.sh /usr/bin/RUN chmod +x /usr/bin/entrypoint.shENTRYPOINT ["entrypoint.sh"]EXPOSE 3000CMD ["rails", "server", "-b", "0.0.0.0"]
#routes.rb
require 'sidekiq/web'Rails.application.routes.draw do mount Sidekiq::Web => '/sidekiq' ...other routesend
#sidekiq.rb
sidekiq_config = { url: ENV['REDIS_URL'] }Sidekiq.configure_server do |config| config.redis = sidekiq_configendSidekiq.configure_client do |config| config.redis = sidekiq_configend
#.env
REDIS_URL=redis://redis:6379/0
Please tell me if I missed some configuration file or where I am wrong with the settings?