[英]Sidekiq Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) on docker-compose
[英]rails + docker + sidekiq + Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
運行帶有docker和docker-compose的rails應用程序時出現此錯誤錯誤連接到127.0.0.1:6379上的Redis(Errno :: ECONNREFUSED)
請找到我的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
提前致謝!
我使用.env
-compose並添加.env
文件
REDIS_URL=redis://redis:6379/0
啟用服務進行通信不需要鏈接 - 默認情況下,任何服務都可以通過該服務的名稱訪問任何其他服務。
根據您的docker-compose.yaml文件,您只能從主機訪問127.0.0.1:6379上的redis容器。
容器在其網絡中相互通信,因此您可以從rails app容器訪問redis上的redis容器redis:6379
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.