docker run -it --name kafka01 -p 19092:9092 -d -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.233.129:12181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.233.129:19092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka:latest 根据这条命令帮我写个docker-compose
时间: 2024-04-11 07:28:47 浏览: 32
Certainly! Here's the equivalent `docker-compose.yml` file for the given Docker command:
```yaml
version: '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
```
You can save this content into a file named `docker-compose.yml` and run `docker-compose up -d` to start the Kafka container.
相关问题
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 这两天帮我整合在一起
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.
docker-compose安装kafka kraft
以下是使用docker-compose安装kafka kraft的步骤:
1. 创建一个名为`docker-compose.yml`的文件,并在其中定义kafka和zookeeper的服务配置。
```yaml
version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:6.2.0
container_name: zookeeper
ports:
- "2181:2181"
environment:
- ZOOKEEPER_CLIENT_PORT=2181
- ZOOKEEPER_TICK_TIME=2000
kafka:
image: confluentinc/cp-kafka:6.2.0
container_name: kafka
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
- KAFKA_BROKER_ID=1
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
- KAFKA_AUTO_CREATE_TOPICS_ENABLE=false
```
2. 打开终端,进入包含`docker-compose.yml`文件的目录,并运行以下命令启动kafka和zookeeper服务。
```shell
docker-compose up -d
```
3. 等待一段时间,直到所有容器启动并运行。可以使用以下命令检查容器的状态。
```shell
docker-compose ps
```
4. 现在,你的kafka和zookeeper服务已经在Docker容器中成功安装和运行了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)