[英]Event listener on Docker using volume mount not working
Some folder is mounted using: 使用以下方式挂载某些文件夹:
docker run -it C:\Users\User\Documents\project\input:/app/input/ project:latest
In the container a Python a watchdog.observers
instance is running to detect if new files are added to the host folder. 在Python容器中,一个
watchdog.observers
实例正在运行,以检测是否有新文件添加到主机文件夹中。 These files end up in the Docker container via the volume mount. 这些文件通过卷挂载最终存储在Docker容器中。 The file created event trigger does not reach the Docker container.
文件创建的事件触发器未到达Docker容器。 I think this is strange because in the Docker container events are also happening right?
我认为这很奇怪,因为在Docker容器中事件也正在发生吗?
When I run my code locally and not in Docker the eventlistener it is working. 当我在本地而不是在Docker中运行代码时,eventlistener正在运行。
Does event listening work in my context? 事件侦听在我的上下文中有用吗?
main.py main.py
from watch import ImagesWatcher
if __name__ == '__main__':
src_path = "/app/input/"
ImagesWatcher(src_path).run()
watch.py watch.py
import sys
import time
from watchdog.observers import Observer
from ImagesEventHandler import ImagesEventHandler
class ImagesWatcher:
def __init__(self, src_path):
self.__src_path = src_path
self.__event_handler = ImagesEventHandler()
self.__event_observer = Observer()
def run(self):
self.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
self.stop()
def start(self):
self.__schedule()
self.__event_observer.start()
def stop(self):
self.__event_observer.stop()
self.__event_observer.join()
def __schedule(self):
self.__event_observer.schedule(
self.__event_handler,
self.__src_path,
recursive=True
)
if __name__ == "__main__":
src_path = sys.argv[1] if len(sys.argv) > 1 else '.'
ImagesWatcher(src_path).run()
imagesEventHandler.py imagesEventHandler.py
from watchdog.events import RegexMatchingEventHandler
class ImagesEventHandler(RegexMatchingEventHandler):
THUMBNAIL_SIZE = (128, 128)
IMAGES_REGEX = [r".*[^_thumbnail]\.jpg$"]
def __init__(self):
# self.Analyzer = Analyzer()
super().__init__(self.IMAGES_REGEX)
def on_created(self, event):
self.process(event)
def process(self, event):
print("DETECTED")
Dockerfile: Dockerfile:
FROM python:3.6
RUN pip install watchdog
ADD . .
WORKDIR /app/
RUN main.py
一位同事向我推荐了以下内容: https : //github.com/merofeev/docker-windows-volume-watcher
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.