kafka kraft docker compose环境变量配置
时间: 2023-11-30 08:43:22 浏览: 159
环境变量配置
根据提供的引用内容,我理解您想了解如何在kafka kraft docker compose环境中配置环境变量。具体操作步骤如下:
1. 在docker-compose.yml文件中添加环境变量配置,例如:
```yaml
version: '3'
services:
kafka:
image: wurstmeister/kafka:2.13-2.7.0
container_name: kafka
environment:
KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
ports:
- "9092:9092"
depends_on:
- zookeeper
zookeeper:
image: wurstmeister/zookeeper:3.4.6
container_name: zookeeper
ports:
- "2181:2181"
```
在上述示例中,我们在kafka服务中添加了三个环境变量配置,分别为KAFKA_ADVERTISED_HOST_NAME、KAFKA_ADVERTISED_PORT和KAFKA_ZOOKEEPER_CONNECT。
2. 在kafka服务中使用环境变量,例如:
```yaml
version: '3'
services:
kafka:
image: wurstmeister/kafka:2.13-2.7.0
container_name: kafka
environment:
KAFKA_ADVERTISED_HOST_NAME: ${KAFKA_ADVERTISED_HOST_NAME}
KAFKA_ADVERTISED_PORT: ${KAFKA_ADVERTISED_PORT}
KAFKA_ZOOKEEPER_CONNECT: ${KAFKA_ZOOKEEPER_CONNECT}
ports:
- "${KAFKA_ADVERTISED_PORT}:${KAFKA_ADVERTISED_PORT}"
depends_on:
- zookeeper
zookeeper:
image: wurstmeister/zookeeper:3.4.6
container_name: zookeeper
ports:
- "2181:2181"
```
在上述示例中,我们使用了${}语法来引用环境变量。
阅读全文