这是我的 Dockerfile:
FROM node:18-slim as builder
WORKDIR /usr/src/ai_api_builder/
COPY package*.json tsconfig.json /usr/src/ai_api_builder/
RUN apt-get update && \
apt-get install mariadb-client -y && \
npm install && npm cache clean --force
RUN apt install ffmpeg -y && \
ffmpeg -version && \
ffprobe -version
COPY ${REPO_DIR}/ ./
RUN npm run build && mv audio_store node_modules dist/
FROM node:18-slim
# Create and cd into app directory
WORKDIR /usr/src/dwt_api_app/dist
# Copy the artifact to the new image
COPY --from=builder /usr/src/dwt_api_builder/dist ./
EXPOSE 3001
ENTRYPOINT ["node", "app.js"]
当我构建 Dockerfile 时,检查 ffmpeg 和 ffprobe 版本的步骤有效:
ffmpeg version 5.1.4-0+deb12u1 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Debian 12.2.0-14)
...
ffprobe version 5.1.4-0+deb12u1 Copyright (c) 2007-2023 the FFmpeg developers
但是当我运行容器时,我的 TypeScript 代码不起作用(元数据返回
undefined
):
import { ffprobe } from "fluent-ffmpeg";
ffprobe(latestFilePath, async function(err: any, metadata: any) {
console.log("metadata", metadata);
})
当我执行容器并检查
ffmpeg -version
和 ffprobe -version
时,我得到:bash: ffmpeg: command not found
。当我检查 bin 文件夹时,也找不到ffmpeg
。 ffprobe version 6.1-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2007-2023 the FFmpeg developers <b>
运行容器时我做错了什么步骤或者debian(容器内)和centos 7(本地)之间有什么区别需要注意吗?谢谢
您在
ffmpeg
阶段安装了 ffprobe
和 builder
。这意味着这些工具在最终图像中不可用。
要解决您的问题,请在最后阶段安装这些工具,例如:
FROM node:18-slim as builder
WORKDIR /usr/src/ai_api_builder/
COPY package*.json tsconfig.json /usr/src/ai_api_builder/
RUN apt-get update && \
apt-get install mariadb-client -y && \
npm install && npm cache clean --force
COPY ${REPO_DIR}/ ./
RUN npm run build && mv audio_store node_modules dist/
FROM node:18-slim
RUN apt-get update && apt install ffmpeg -y && \
ffmpeg -version && \
ffprobe -version
# Create and cd into app directory
WORKDIR /usr/src/dwt_api_app/dist
# Copy the artifact to the new image
COPY --from=builder /usr/src/dwt_api_builder/dist ./
EXPOSE 3001
ENTRYPOINT ["node", "app.js"]
更多关于多阶段构建。