我在ubuntu 14.04 LTS机器上运行wurstmeister / kafka。卡夫卡集装箱运行良好。但是我无法将我的微服务连接到这个容器。
Kafka docker-compose.yml:
version: '2'
services:
zookeeper:
image: user1/zookeeper:3.4.9
ports:
- "2181:2181"
kafka:
image: my-kafka
ports:
- "9092:9092"
hostname: kafka-01
environment:
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ADVERTISED_HOST_NAME: "kafka-01"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_CREATE_TOPICS: "topic1:1:1,topic2:1:1"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
docker-compose for microservice(myapp):
version: '2'
services:
myapp:
network_mode: 'bridge'
extends:
file: myapp.base.yml
service: myapp
links:
- kafka
zookeeper:
network_mode: 'bridge'
extends:
file: zookeeper.yml
service: zookeeper
kafka:
network_mode: 'bridge'
extends:
file: kafka.yml
service: kafka
links:
- zookeeper
我在一个环境中链接了kafka:
kafkaHost=kafka-01:9092
请告诉我我做错了什么或者是否需要更多信息。提前谢谢。
答案 0 :(得分:2)
主机名应该是您在“链接”中指定的名称,即。 “海边的卡夫卡”。正如@dnephin所说,不需要主机名。我想你想要的实际上是KAFKA_ADVERTISED_HOST_NAME环境变量。
你有什么版本的码头工具?我在Mac OS上使用docker 1.12.3没有任何问题。
您可能还想尝试使用Confluent泊坞窗图像:
这是我的示例docker compose文件:
version: "2"
services:
web:
image: nginx:latest
links:
- kafka
zookeeper:
extends:
file: kafka-services.yml
service: zookeeper
kafka:
extends:
file: kafka-services.yml
service: kafka
depends_on:
- zookeeper
我的基础kafka服务撰写文件(kafka-services.yml):
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
ports:
- "32181:32181"
environment:
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: confluentinc/cp-kafka:latest
ports:
- "29092:29092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:32181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092
答案 1 :(得分:0)
hostname
字段未设置公共主机名,它设置内部容器主机名。它通常没那么有用。
主机名由docker网络自动提供,使用kafka
作为主机名。