外部Docker,redis和rabbitmq的ip地址在我的django應用程序中設置爲'localhost',位於ubuntu 16.04環境中。但是,我正在嘗試將我的Web服務遷移到docker中。我使用Docker的官方存儲庫redis和rabbitmq。Docker中的Rabbitmq IP地址和Redis IP地址
在我的Django settings.py
中,我必須聲明redis和rabbitmq的IP地址,以便在我的應用程序中連接到它們。我沒有任何線索如何確定他們在Docker內部的IP地址。在泊塢窗-compose.yml,配置如下陳述:
version: '2'
services:
# RabbitMQ
rabbit:
hostname: my-rabbit
image: rabbitmq:3
ports:
- "5672:5672" # we forward this port because it's useful for
debugging
- "15672:15672" # here, we can access rabbitmq management plugin
#Redis
redis:
image: redis:latest
#Data Processing WS
web:
build: .
command: python manage.py runserver 0.0.0.0:9060 --noreload
volumes:
- .:/srv
ports:
- "9060:9060"
links: ["rabbit", "redis"]
當我試圖爲「localhost」的,錯誤發生時
settings.CONNECTION = pika.BlockingConnection(pika.ConnectionParameters(host=settings.RABBIT_MQ_
IP_ADDRESS, heartbeat_interval=0))
web_1 | File "/usr/local/lib/python2.7/dist-
packages/pika/adapters/blocking_connection.py", line 339, in __init__
web_1 | self._process_io_for_connection_setup()
web_1 | File "/usr/local/lib/python2.7/dist-
packages/pika/adapters/blocking_connection.py", line 374, in
_process_io_for_connection_setup
web_1 | self._open_error_result.is_ready)
web_1 | File "/usr/local/lib/python2.7/dist-
packages/pika/adapters/blocking_connection.py", line 395, in _flush_output
web_1 | raise exceptions.ConnectionClosed()
web_1 | pika.exceptions.ConnectionClosed
我試過了,它仍然沒有工作。在進一步的研究,我仍然包括健康檢查: 試驗:[ 「CMD」, 「捲曲」, 「-f」, 「http://172.17.0.3:15672」] 間隔:30秒 超時:10S 重試:5 在我的docker-compose.yml中。任何想法? –
愚蠢的問題,但是在更改'docker-compose.yml'之前運行'docker-compose down'嗎? – grizzthedj
我實際上'ctrl + c'來終止'docker-compose up'並在編輯'docker-compose.yml'後執行'docker-compose build'。這樣好嗎? –