无法从 docker-compose 文件中定义的另一个服务连接到 nsqd
Posted
技术标签:
【中文标题】无法从 docker-compose 文件中定义的另一个服务连接到 nsqd【英文标题】:cannot connect to nsqd from another service defined in docker-compose file 【发布时间】:2020-01-10 05:59:34 【问题描述】:我有一个连接到 nsqd 的服务来生成和使用消息。我有与之连接的集成测试(广播地址 127.0.0.1),并且在 cli 或 ide 中本地执行它可以正常工作。
然后我用 docker-compose 创建了这个服务,但是无法连接到 nsqd。
以下是我的 docker-compose 文件
version: '3'
services:
redis:
image: redis:4.0.9-alpine
ports:
- "6379:6379"
nsqlookupd:
image: nsqio/nsq:v0.3.8
command: /nsqlookupd
ports:
- "4160:4160"
- "4161:4161"
nsqd:
image: nsqio/nsq:v0.3.8
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=127.0.0.1
links:
- nsqlookupd:nsqlookupd
ports:
- "4150:4150"
- "4151:4151"
nsqadmin:
image: nsqio/nsq:v0.3.8
ports:
- "4171:4171"
links:
- nsqlookupd:nsqlookupd
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
creator:
build: "creator/"
depends_on:
- nsqlookupd
- nsqd
- redis
environment:
SERVER_ADDR: ":8080"
NSQ_ADDR: "nsqd:4150"
NSQ_TOPIC: "driver_locations"
NSQ_CHANNEL: "ch"
REDIS: "redis:6379"
ports:
- "8080:8080"
现在我不关心本地测试,只是让所有容器正常工作。
我已尝试更改广播,删除广播... 正如他们在文档https://nsq.io/deployment/docker.html#using-docker-compose 中所说,这是我尝试的最后一件事(基本上更改是命令),但没有运气:
version: '3'
services:
redis:
image: redis:4.0.9-alpine
ports:
- "6379:6379"
nsqlookupd:
image: nsqio/nsq
command: /nsqlookupd
ports:
- "4160"
- "4161"
nsqd:
image: nsqio/nsq
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160
depends_on:
- nsqlookupd
ports:
- "4150"
- "4151"
nsqadmin:
image: nsqio/nsq
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
depends_on:
- nsqlookupd
ports:
- "4171"
creator:
build: "creator/"
depends_on:
- nsqlookupd
- nsqd
- redis
environment:
SERVER_ADDR: ":8080"
NSQ_ADDR: "nsqd:4150"
NSQ_TOPIC: "driver_locations"
NSQ_CHANNEL: "ch"
REDIS: "redis:6379"
ports:
- "8080:8080"
【问题讨论】:
【参考方案1】:缓存问题,抱歉:facepalm:
我告诉它不起作用(删除广播)它是
我尝试过更改广播,删除广播... 正如他们在文档https://nsq.io/deployment/docker.html#using-docker-compose 中所说,这是我尝试的最后一件事(基本上更改是命令),但没有运气:
version: '3'
services:
redis:
image: redis:4.0.9-alpine
ports:
- "6379:6379"
nsqlookupd:
image: nsqio/nsq
command: /nsqlookupd
ports:
- "4160"
- "4161"
nsqd:
image: nsqio/nsq
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160
depends_on:
- nsqlookupd
ports:
- "4150"
- "4151"
nsqadmin:
image: nsqio/nsq
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
depends_on:
- nsqlookupd
ports:
- "4171"
creator:
build: "creator/"
depends_on:
- nsqlookupd
- nsqd
- redis
environment:
SERVER_ADDR: ":8080"
NSQ_ADDR: "nsqd:4150"
NSQ_TOPIC: "driver_locations"
NSQ_CHANNEL: "ch"
REDIS: "redis:6379"
ports:
- "8080:8080"
【讨论】:
以上是关于无法从 docker-compose 文件中定义的另一个服务连接到 nsqd的主要内容,如果未能解决你的问题,请参考以下文章