1.参考:
https://blog.csdn.net/m0_57609406/article/details/140323327
2.dockerfile命令
# 使用官方 Python 基础镜像
FROM python:3.8.18-slim# 设置工作目录
WORKDIR /usr/src/app# 安装必要的软件包(FFmpeg、OpenCV、lsof、RTSP工具)
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free" > /etc/apt/sources.list && \echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free" >> /etc/apt/sources.list && \echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list && \apt-get update && apt-get install -y \wget \vim \ffmpeg \lsof \libgl1-mesa-glx \libglib2.0-0 \python3-opencv \&& apt-get clean && rm -rf /var/lib/apt/lists/*# 下载并安装 RTSP Simple Server
RUN wget https://github.com/aler9/rtsp-simple-server/releases/download/v0.17.0/rtsp-simple-server_v0.17.0_linux_amd64.tar.gz \&& tar -zxvf rtsp-simple-server_v0.17.0_linux_amd64.tar.gz \&& rm rtsp-simple-server_v0.17.0_linux_amd64.tar.gz# 复制依赖文件并安装
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt# 复制项目代码到容器
COPY . .# 暴露 Flask 和 RTSP 端口
EXPOSE 11115
EXPOSE 8554
EXPOSE 5004# 启动 RTSP 服务和项目应用
CMD ["bash", "-c", "./rtsp-simple-server & ffmpeg -re -stream_loop -1 -i fire.mp4 -c:v copy -f rtsp rtsp://0.0.0.0:8554/stream & python app.py"]
3.docker命令
docker build -t rtsp-server-app .
docker run -d --name rtsp-container -p 11115:11115 -p 8554:8554 rtsp-server-app
4.运行
打开http://localhost:11115/