简体   繁体   English

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)

I am getting this error while running my rails app with docker and docker-compose Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) 运行带有docker和docker-compose的rails应用程序时出现此错误错误连接到127.0.0.1:6379上的Redis(Errno :: ECONNREFUSED)

Please find my Docker file 请找到我的Docker文件

# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5

# Copy the main application.
COPY . ./app

# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000

# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

Please find my docker-compose.yml file 请找到我的docker-compose.yml文件

version: "2"
services:
  redis:
    image: redis
    command: redis-server
    ports:
      - "6379:6379"
  postgres:
    image: postgres:9.4
    ports:
      - "5432"

  app:
    build: .
    command: rails server -p 3000 -b '0.0.0.0'
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    links:
      - postgres
      - redis
      - sidekiq

  sidekiq:
    build: .
    command: bundle exec sidekiq
    depends_on:
      - redis
    volumes:
      - .:/app
    env_file:
      - .env

Thanks in Advance! 提前致谢!

我使用.env -compose并添加.env文件

REDIS_URL=redis://redis:6379/0

Links are not required to enable services to communicate - by default, any service can reach any other service at that service's name. 启用服务进行通信不需要链接 - 默认情况下,任何服务都可以通过该服务的名称访问任何其他服务。

According to your docker-compose.yaml file you can access you redis container on 127.0.0.1:6379 only from host machine. 根据您的docker-compose.yaml文件,您只能从主机访问127.0.0.1:6379上的redis容器。

Containers communicate with each other in their network, so you can access your redis container on redis:6379 from rails app container. 容器在其网络中相互通信,因此您可以从rails app容器访问redis上的redis容器redis:6379

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 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 在 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错 - Wercker - Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) - Wercker Rails-Redis :: CannotConnectError:在本地主机上连接Redis时出错:6379(Errno :: ECONNREFUSED) - Rails - Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) 在 Rails 应用程序上的 127.0.0.1:6379(ECONNREFUSED) 上连接到 Redis 时出错 - Error connecting to Redis on 127.0.0.1:6379(ECONNREFUSED) on rails application (在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): Sidekiq Redis :: CannotConnectError:生产时在127.0.0.1:6379上连接到Redis时出错 - Sidekiq Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 on production Redis :: CannotConnectError(在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): 想在Heroku上使用Redis(Redis :: CannotConnectError(在127.0.0.1:6379上连接到Redis时出错(ECONNREFUSED))) - Want to use Redis on Heroku (Redis::CannotConnectError ( Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)) ) Redis / Resque [在本地主机上连接到Redis时出错:6379(ECONNREFUSED)] - Redis/Resque [Error connecting to Redis on localhost:6379 (ECONNREFUSED)] GiLab CI-Redis :: CannotConnectError:在127.0.0.1:6379上连接到Redis时出错 - GiLab CI - Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM