ruby-on-rails - rails + docker + sidekiq + 在 127.0.0.1:6379 上连接到 Redis 时出错(Errno::ECONNREFUSED)

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

我在使用 docker 和 docker-compose 运行我的 rails 应用程序时遇到此错误 在 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错

请找到我的 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"]

请找到我的 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

提前致谢!

最佳答案

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

REDIS_URL=redis://redis:6379/0

关于ruby-on-rails - rails + docker + sidekiq + 在 127.0.0.1:6379 上连接到 Redis 时出错(Errno::ECONNREFUSED),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48802444/

相关文章:

caching - Redis 作为缓存 - 重置过期

mysql - Github 喜欢数据模式?

redis - Booksleeve Redis 开发指南

ruby-on-rails - Oauth 2.0 错误 领英

ruby-on-rails - 强制重新加载自动加载的库文件所需的库文件

linux - 将 DATA (Dev-Environments/apps/etc) 分区与 Linux 系统最小尺寸 OS 分区分开的简单方法? Docker 还是 Overlayfs Overlayroot?其他?

Docker - 镜像操作系统 "windows"无法在此平台上使用

ruby-on-rails - Rails 4 将参数从一个 Controller 传递到另一个 Controller

ruby-on-rails - Rails + Graphql - 无法实现 Game.id

Docker CMD 无法添加新用户,权限被拒绝