docker - 是否可以使用属性文件而不是环境变量来启动/配置融合的Docker镜像?

标签 docker apache-kafka apache-zookeeper confluent-platform

The docs指出cp-zookeeper和cp-kafka镜像是通过环境变量配置的。

The ZooKeeper image uses variables prefixed with ZOOKEEPER_ with the variables expressed exactly as they would appear in the zookeeper.properties file. As an example, to set clientPort, tickTime, and syncLimit run the command below:


 docker run -d \
--net=host \
--name=zookeeper \
-e ZOOKEEPER_CLIENT_PORT=32181 \
-e ZOOKEEPER_TICK_TIME=2000 \
-e ZOOKEEPER_SYNC_LIMIT=2
confluentinc/cp-zookeeper:3.3.1

我宁愿提供zookeeper.properties(kafka的server.properties),而不是指定ZOOKEEPER_ *(KAFKA_ *)环境变量。这可能吗?

在我当前使用“非融合” kafka进行的设置中,我只是在/ etc / kafka上挂载了包含属性的配置卷,然后从中启动kafka,但查看confluent docker images,我发现它不起作用,因为有一些特殊之处为了在容器内部生成属性,进行了模板魔术。

最佳答案

您可以通过在docker命令中使用--env-file开关而不是在命令行中键入每个环境变量来实现您所描述的内容。

例如,如果您首先将所需的属性存储到文件中,则说kafka.properties:

KAFKA_ZOOKEEPER_CONNECT=localhost:32181
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:29092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1

那么您可以通过运行以下命令来启动您的kafka容器:
docker run -d --net=host --name=kafka --env-file ./kafka.properties confluentinc/cp-kafka:3.3.1
尽管如此,属性键的名称应与每个docker镜像所期望的相匹配(如您所注意到的,当每个docker镜像运行时,它们会呈现给相应的服务属性)。

关于docker - 是否可以使用属性文件而不是环境变量来启动/配置融合的Docker镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47434928/

相关文章:

apache-kafka - 如何将 Kafka promise 的消费者偏移量更改为所需的偏移量

docker - 带有远程Docker守护程序的Packer Docker Builder

java - Apiman 不恢复网关

sqlite - 是否可以通过 docker golang :alpine image? 构建静态 sqlite Go 应用程序

angular - `try_files`无法与Nginx Docker镜像一起使用

apache-kafka - 对新列使用不同的 avro 架构

azure - 无法连接到在 Azure 应用服务上运行的 KAFKA

java - APK reference.conf 中复制的重复文件

python - 当 zookeeper 的状态自动改变时,Watches 和 Ephemeral 节点不工作?

java - Storm KafkaSpout 停止消费来自 Kafka Topic 的消息