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 给坐上持久化
时间: 2024-04-11 17:28:48 浏览: 158
Apache Kafka 3.2.0 (Scala 2.13 :kafka_2.13-3.2.0.tgz)
To add persistence to the Kafka container, you can add a volume to the `docker-compose.yml` file. Here's an updated version with persistence:
```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
volumes:
- ./kafka/data:/kafka/data
- ./kafka/logs:/kafka/logs
```
In this updated configuration, two volumes are added: `./kafka/data` and `./kafka/logs`. These volumes will map the Kafka container's data and logs directories to the corresponding directories on the host machine, allowing for persistence of data and logs even if the container is recreated.
Make sure to create the `kafka/data` and `kafka/logs` directories in the same location as your `docker-compose.yml` file before running `docker-compose up -d`.
阅读全文