Sidekiq Error connecting to Redis on (Errno::ECONNREFUSED) on docker-compose

I’m trying to run sidekiq worker with Rails. When I try to docker-compose up worker I get the following error:

worker_1 | Error connecting to Redis on (Errno::ECONNREFUSED)
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:332:in `rescue in establish_connection'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:318:in `establish_connection'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:94:in `block in connect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:93:in `connect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:351:in `ensure_connected'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:208:in `block in process'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:293:in `logging'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:207:in `process'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:113:in `call'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:211:in `block in info'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'
worker_1 | /usr/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:210:in `info'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq/cli.rb:71:in `block in run'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq.rb:84:in `block in redis'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:64:in `block (2 levels) in with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `handle_interrupt'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `block in with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `handle_interrupt'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq.rb:81:in `redis'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq/cli.rb:68:in `run'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/bin/sidekiq:13:in `<top (required)>'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `load'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `<main>'
nyvur_worker_1 exited with code 1

Here’s my docker-compose file:

  • Error response from daemon: Container CONTAINER_NAME is not running
  • Spring on docker, environment variables not evaluated with configuration placeholders
  • Start supervisor by non root user
  • Docker can not resolve names when building images
  • WordPress, Docker and nginx
  • Slow network in Docker container after OpenShift install
  • web: &app_base
      build: .
        - "80:80"
        - .:/Nyvur
      command: /usr/bin/
        - postgres
        - mongo
        - redis
      environment: &app_environment
        RACK_ENV: production
        RAILS_ENV: production
      build: .
        - .:/Nyvur
      ports: []
        - postgres
        - mongo
        - redis
      command: bundle exec sidekiq -c 50
      image: postgres:9.1
        - "5432:5432"
        LC_ALL: C.UTF-8
        POSTGRES_DB: Nyvur_production
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: 3x1mpl3
      image: mongo:3.0.7
        - "27017:27017"
      image: redis
        - "6379:6379"

    My Dockerfile:

    FROM phusion/passenger-customizable
    ENV RACK_ENV="production" RAILS_ENV="production"
    ENV HOME /root
    CMD ["/sbin/my_init"]
    RUN /pd_build/
    RUN /pd_build/
    RUN /pd_build/
    RUN /pd_build/
    RUN /pd_build/
    RUN /pd_build/
    RUN apt-get update && apt-get install -y vim nano dialog net-tools build-essential wget libpq-dev git
    RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    # RUN mkdir /etc/nginx/ssl
    # RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
    RUN rm -f /etc/service/nginx/down
    RUN rm -f /etc/service/redis/down
    RUN rm -f /etc/service/sshd/down
    RUN rm -f /etc/service/memcached/down
    WORKDIR /tmp
    ADD Gemfile /tmp/
    ADD Gemfile.lock /tmp/
    RUN mkdir /home/app/Nyvur
    ADD . /home/app/Nyvur
    RUN chown -R app:app /home/app/Nyvur
    WORKDIR /home/app/Nyvur
    RUN bundle install --deployment
    RUN bundle exec rake assets:precompile
    RUN rm /etc/nginx/sites-enabled/default
    COPY config/nginx/nginx_nyvur.conf /etc/nginx/sites-enabled/nginx_nyvur.conf
    ADD config/nginx/postgres-env.conf /etc/nginx/main.d/postgres-env.conf
    ADD config/nginx/rails-env.conf /etc/nginx/main.d/rails-env.conf
    ADD config/nginx/ /usr/bin/
    RUN chmod +x /usr/bin/
    RUN mkdir -p /home/app/Nyvur/tmp/pids
    RUN mkdir -p /home/app/Nyvur/tmp/sockets
    RUN mkdir -p /home/app/Nyvur/log
    RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    EXPOSE 80 443 9292

    I’ve tried different configurations, I’ve checked other builds, but the problem still persists, So far, Sidekiq runs well outside of Docker.

  • How do I SSH into the boot2docker host vm that the Vagrant 1.6 Docker Provider sets up?
  • Issue with docker push on local registry https access to ressource denied
  • How to run Iojs in Docker?
  • Can not ping docker in macOS
  • Mongodb won't start in Docker container when remote-mounting a volume from host
  • How to get memory usage of processes running in docker container?
  • 3 Solutions collect form web for “Sidekiq Error connecting to Redis on (Errno::ECONNREFUSED) on docker-compose”

    Error connecting to Redis on (Errno::ECONNREFUSED)

    Your app tries to connect on the localhost interface of the container it is running in, but redis is running in a different container.

    Modify your app config to use the link name of the redis container (redis in your case) as hostname for the connection.

    Check if your redis server is running, start redis by using the following command in the terminal:


    Just start your redis server by using redis-server command.
    After start sidekiq

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.