保留所有kafka主题的数据并注入不同的实例
Persisting data of all kafka topics and injecting into a different instance
我在 docker 图像中有一个 kafka 集群。
1)我想在每次 docker 图像启动时向 kafka 主题中注入数据。这是 docker 启动
的一部分的一次性初始化过程
2) 上述步骤中使用的初始化数据来自预定义的场景。因此,数据将在主题中可用(作为预定义场景的一部分)。对于上述步骤 1
,如何将此数据保存到文件并注入 docker 启动
我在 dockerhub 中查找但找不到任何相关图片。
我建议尽可能将此作为 build
步骤的一部分。如果您将它作为构建的一部分进行,它将被缓存,并且您不必在每次启动容器时都重复它。
我在持久性存储(数据库)中使用的模式是这样的构建步骤:
Docker 文件:
...
COPY setup.sh /code/setup.sh
RUN /code/setup.sh
...
setup.sh(这是伪代码)
./start_kafka.sh & # start the service in the background
./wait_for_kafka_to_be_available.sh # If the service comes with good init scripts, they might already do this for you
./populate_data.sh # run a client which puts data into the queue
./stop_kafka.sh # Do a clean shutdown, a proper init script might provide this as well
现在当容器启动时,它应该会更快地读取持久化数据和启动。
如果由于某种原因您不能这样做,而您需要在 运行time 时间这样做,您最好使用一些初始化系统。您可以在此处 https://github.com/dnephin/docker-swarm-slave 找到一个示例(使用 s6 作为 init 系统)。它启动两项服务(dind
和 swarm-slave
),在您的情况下,其中一项服务将 运行 wait_for_kafka_to_be_available.sh
和 ./populate_data.sh
然后退出。
我在 docker 图像中有一个 kafka 集群。
1)我想在每次 docker 图像启动时向 kafka 主题中注入数据。这是 docker 启动
的一部分的一次性初始化过程2) 上述步骤中使用的初始化数据来自预定义的场景。因此,数据将在主题中可用(作为预定义场景的一部分)。对于上述步骤 1
,如何将此数据保存到文件并注入 docker 启动我在 dockerhub 中查找但找不到任何相关图片。
我建议尽可能将此作为 build
步骤的一部分。如果您将它作为构建的一部分进行,它将被缓存,并且您不必在每次启动容器时都重复它。
我在持久性存储(数据库)中使用的模式是这样的构建步骤:
Docker 文件:
...
COPY setup.sh /code/setup.sh
RUN /code/setup.sh
...
setup.sh(这是伪代码)
./start_kafka.sh & # start the service in the background
./wait_for_kafka_to_be_available.sh # If the service comes with good init scripts, they might already do this for you
./populate_data.sh # run a client which puts data into the queue
./stop_kafka.sh # Do a clean shutdown, a proper init script might provide this as well
现在当容器启动时,它应该会更快地读取持久化数据和启动。
如果由于某种原因您不能这样做,而您需要在 运行time 时间这样做,您最好使用一些初始化系统。您可以在此处 https://github.com/dnephin/docker-swarm-slave 找到一个示例(使用 s6 作为 init 系统)。它启动两项服务(dind
和 swarm-slave
),在您的情况下,其中一项服务将 运行 wait_for_kafka_to_be_available.sh
和 ./populate_data.sh
然后退出。