Here is my 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"]
When I build Dockerfile, the step check ffmpeg and ffprobe version worked:
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
But when I run container, my TypeScript code not work (the metadata return undefined
):
import { ffprobe } from "fluent-ffmpeg";
ffprobe(latestFilePath, async function(err: any, metadata: any) {
console.log("metadata", metadata);
})
When I exec to container and check ffmpeg -version
and ffprobe -version
, I got: bash: ffmpeg: command not found
. And when I check in bin folder, also couldn't find ffmpeg
.
I tried it locally (Centos7), not in container, it worked (metadata return an object), and here is ffprobe version
ffprobe version 6.1-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2007-2023 the FFmpeg developers <b>
What step did I do wrong when running the container or is there any difference between debian (in container) and centos 7 (local) that I need to pay attention to? Thanks
You installed ffmpeg
and ffprobe
in the builder
stage. This means those tools are not available in the final image.
To fix your issue install these tools in your final stage like:
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"]
More about multi-stage builds.