-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (64 loc) · 2.28 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 使用一个基于 Debian 的 Python 镜像作为统一的基础镜像
FROM python:3.9-slim-bookworm
# 设置工作目录
WORKDIR /app
# [可选] 如果你需要使用国内的 apt 源,可以保留这一步
COPY sources.list /etc/apt/sources.list
# 一条 RUN 指令完成所有编译和清理工作,以减小镜像层数和体积
RUN export DEBIAN_FRONTEND=noninteractive && \
# 1. 更新 apt 并安装编译 FFmpeg 所需的依赖
apt-get -qq update && \
apt-get -qq install --no-install-recommends \
build-essential \
git \
pkg-config \
yasm \
ca-certificates && \
\
# 2. 克隆 FFmpeg 源码
git clone https://bgithub.xyz/FFmpeg/FFmpeg.git --depth 1 --branch n6.1.1 --single-branch /tmp/FFmpeg-6.1.1 && \
cd /tmp/FFmpeg-6.1.1 && \
\
# 3. 配置和编译 FFmpeg
# 注意:安装到 /usr/local,这样 ffmpeg 命令可以直接在 PATH 中找到
./configure \
--prefix="/usr/local" \
--pkg-config-flags="--static" \
--extra-cflags="-I/usr/local/include" \
--extra-ldflags="-L/usr/local/lib" \
--extra-libs="-lpthread -lm" \
--ld="g++" \
--disable-doc \
--disable-htmlpages \
--disable-podpages \
--disable-txtpages \
--disable-network \
--disable-autodetect \
--disable-hwaccels \
--disable-ffprobe \
--disable-ffplay \
--enable-filter=copy \
--enable-protocol=file \
--enable-small && \
make -j$(nproc) && \
make install && \
\
# 4. 关键步骤:清理!
# 删除 FFmpeg 源码
cd / && rm -rf /tmp/FFmpeg-6.1.1 && \
# 卸载所有编译时依赖
apt-get purge -y --auto-remove build-essential git pkg-config yasm && \
# 清理 apt 缓存
rm -rf /var/lib/apt/lists/*
# 复制应用程序代码
COPY requirements.txt .
COPY main.py .
COPY asr_funasr.py .
COPY health_check.py .
# 安装 Python 依赖,并使用 --no-cache-dir 减小体积
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir torch==2.2.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cpu && \
pip install --no-cache-dir -r requirements.txt
# 设置启动命令
CMD ["python", "main.py"]