找不到模块卡夫卡

时间:2019-07-24 15:17:55

标签: python docker kafka-python

我有一个员工Kafka Queues的python项目,该项目按预期运行,但作为docker容器的一部分运行时无法运行。它不断抛出此错误can't find the module kafka

这就是我的Dockerfile的方式。

FROM ubuntu:18.04

RUN  apt-get update
RUN  apt -y upgrade
RUN  apt-get install -y python
RUN  apt install -y python3-pip
RUN  apt-get install -y libsnappy-dev

RUN mkdir -p /app
WORKDIR /app
COPY . /app

RUN python3 -m pip install pip --upgrade
RUN python3 -m pip install pkgconfig
RUN python3 -m pip install kafka-python
RUN python3 -m pip install -r requirements.txt

CMD python __init__.py

这是我的python脚本,引发错误...

import multiprocessing
from kafka import KafkaConsumer


class Consumer(multiprocessing.Process):
    def __init__(self,host,topic,groupid):
        multiprocessing.Process.__init__(self)
        self.stop_event = multiprocessing.Event()
        self.topic = topic
        self.consumer = KafkaConsumer(
            bootstrap_servers=host,
            auto_offset_reset='earliest',
            enable_auto_commit=True,
            auto_commit_interval_ms=1000,
            consumer_timeout_ms=1000,
            group_id=groupid
        )
    def stop(self):
        self.stop_event.set()

    def run(self,topic,cb):
        self.consumer.subscribe([topic])
        while not self.stop_event.is_set():
            for message in self.consumer:
                cb(message.value)
                if self.stop_event.is_set():
                    break

我确信此行正在安装模块

RUN python3 -m pip install Kafka-python

但是脚本找不到它。

0 个答案:

没有答案