version: '3' services: zookeeper: image: wurstmeister/zookeeper:latest ports: - 12181:2181 container_name: zookeeper tty: true restart: alwaysversion: '3' services: kafka01: image: wurstmeister/kafka:latest ports: - 19092:9092 environment: - KAFKA_BROKER_ID=0 - KAFKA_ZOOKEEPER_CONNECT=192.168.233.129:12181 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.233.129:19092 - KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 container_name: kafka01 tty: true restart: always 这两天帮我整合在一起
时间: 2024-04-11 22:28:47 浏览: 17
Certainly! Here's the combined `docker-compose.yml` file for both ZooKeeper and Kafka:
```yaml
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper:latest
ports:
- 12181:2181
container_name: zookeeper
tty: true
restart: always
kafka01:
image: wurstmeister/kafka:latest
ports:
- 19092:9092
environment:
- KAFKA_BROKER_ID=0
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka01:19092
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
container_name: kafka01
depends_on:
- zookeeper
tty: true
restart: always
```
In this configuration, both ZooKeeper and Kafka are defined as separate services within the same `docker-compose.yml` file. The Kafka service depends on the ZooKeeper service using the `depends_on` keyword. You can save this content into a file named `docker-compose.yml` and run `docker-compose up -d` to start both containers.