【问题标题】:Signals sent to the child process from a parent process is ignored inside a docker container从父进程发送到子进程的信号在 docker 容器内被忽略
【发布时间】:2023-03-16 23:26:01
【问题描述】:

我有一个使用 FastAPI 构建的 Python REST API 服务器。响应后,它会生成一个 ffmpeg 子进程,该子进程用于从 IP 摄像机提供的 RTSP 流中捕获视频。根据另一个请求,应用程序通过向 ffmpeg 进程发送 SIGTERM 信号来停止录制视频。

这在 Docker 之外工作得很好,但是在容器中, SIGTERM 被 ffmpeg 进程忽略,因此视频永远不会停止录制。我尝试将 --init 选项添加到我的容器中,但它没有帮助,尽管我的应用不再具有 PID 1。

我的 Dockerfile:

# convert poetry's pyproject.toml into a requirements.txt file
FROM python:3.9 as requirements-stage
WORKDIR /tmp
RUN pip install poetry
COPY ./pyproject.toml ./poetry.lock* /tmp/
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

# actual app deployment
FROM python:3.9
RUN apt update && apt install -y usbutils zlib1g libjpeg-dev ffmpeg
WORKDIR /
COPY --from=requirements-stage /tmp/requirements.txt /requirements.txt
RUN pip install --no-cache-dir --upgrade -r /requirements.txt
COPY . /
ENV IS_DOCKERIZED true
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]

我的 docker-compose.yml:

version: "3.7"
services:
  ipfs_node:
    image: ipfs/go-ipfs:v0.8.0
    volumes:
      - ~/ipfs/ipfs_staging:/export
      - ~/ipfs/ipfs_data:/data/ipfs
    ports:
      - "5001:5001"
      - "8080:8080"
      - "4001:4001"

  feecc_io_gateway:
    build:
      context: ./
      dockerfile: Dockerfile
    init: true
    network_mode: "host"
    volumes:
      - "./output:/output"
      - "/dev/usb:/dev/usb"
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"

【问题讨论】:

    标签: python-3.x docker ffmpeg docker-compose fastapi


    【解决方案1】:

    当我试图弄清楚这一点时,我在 Docker 论坛上创建了另一个 topic。

    我们无法使用信号使其工作,但我找到了一种解决方法。在我使用 ffmpeg 的情况下,我可以将“Q”键发送到标准输入,而不是向进程发送 SIGTERM / SIGINT 信号。这对我有用。

    【讨论】:

      猜你喜欢
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      相关资源
      最近更新 更多