简体   繁体   English

将 Pulsar 和 Python 组合成 docker-compose.yaml

[英]Combine Pulsar and Python into docker-compose.yaml

Background :背景

I've setup up a standalone Pulsar locally and used Pulsar's python api docs to execute a simple consumer and producer modules.我在本地设置了一个独立的 Pulsar ,并使用 Pulsar 的python api 文档来执行一个简单的消费者和生产者模块。

Problem:问题:

Transfer basic workflow into docker-compose.yaml将基本工作流转移到 docker-compose.yaml

  1. Setup up standalone Pulsar locally.在本地设置独立的 Pulsar
  2. Install requirements.txt with needed for consumer.py and producer.py modules安装requirements.txt 和需要的consumer.pyproducer.py模块
  3. Run consumer.py运行consumer.py
  4. Run producer.py运行producer.py

What I've done so far:到目前为止我所做的:

I've figured out how to compose the Pulsar standalone with the following yaml configuration我已经想出了如何使用以下 yaml 配置独立组合 Pulsar

Current pulsar image:当前脉冲星图像:

version: '3.8'
services:
  standalone:
    image: apachepulsar/pulsar:2.8.1
    ports:
      - 8080:8080
      - 6650:6650
    command: bin/pulsar standalone

Where I'm lost我迷路的地方

But I'm struggling conceptually with how I add Python 3.8 and the requirements need in the API docs to then be able to run the python commands python consumer.py and python producer.py但是我在概念上苦苦挣扎于如何添加 Python 3.8 以及 API 文档中的要求,然后才能运行 python 命令python consumer.pypython producer.py

You don't really need another image.你真的不需要另一个图像。 You should keep your code running locally and point it at pulsar image.您应该让您的代码在本地运行并将其指向脉冲星图像。

If you really wanted to run a python docker image, you could do something like this, where example_default is a network name created by compose...如果你真的想运行一个 python docker 镜像,你可以做这样的事情,其中example_default是一个由 compose 创建的网络名称...

docker run --network=example_default -v /path/to/code:/app python:3 /app/producer.py

You will also need to modify your code to not use localhost as the Pulsar server address您还需要修改代码以不使用localhost作为 Pulsar 服务器地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM