skip to Main Content

I am trying to run my docker image on AWS EC2 Instance. However, I am having a trouble with the image file. When I run a task in AWS ECS, it says:

Could not find ffmpeg executable, tried "/srv/linux-x64/ffmpeg", "/srv/app/node_modules/@ffmpeg-installer/linux-x64/ffmpeg" and "/srv/app/node_modules/@ffmpeg-installer/linux-x64/ffmpeg"

This is my Dockerfile:

FROM node:latest as server
WORKDIR /srv/app
COPY ./server/package*.json ./
RUN apt-get update && apt-get install -y 'ffmpeg'
RUN npm install
COPY ./server .
RUN npm run build

FROM node:latest as client
WORKDIR /srv/app
COPY ./client/package*.json ./
RUN npm install
COPY ./client .
RUN npm run build

FROM node:latest as production
WORKDIR /srv/app
RUN mkdir /public
COPY --from=server /srv/app/dist ./
COPY --from=client /srv/app/dist ./public
ENV NODE_ENV=production
EXPOSE 5000
CMD ["node", "app.js"]

This is my package.json:

  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@ffmpeg-installer/ffmpeg": "^1.1.0",
    "@types/ffmpeg": "^1.0.7",
    "@types/fluent-ffmpeg": "^2.1.24"
  }

This is how I used ffmpeg in my code:

import ffmpegPath from '@ffmpeg-installer/ffmpeg';
import ffmpeg from 'fluent-ffmpeg';
ffmpeg.setFfmpegPath(ffmpegPath.path);

Please help me fix this error.

2

Answers


  1. As @David Maze said in a comment above, you’re only installing ffmpeg in the first image.

    One alternative way to address installing the package in each image would be to create a "base" image which adds common config, packages, etc. on top of node:latest and is then extended by each of your component images. This arguably adds some runtime bloat, so you could either only use it in the images where it’s required or use it throughout and potentially move other common environment and config setup into it.

    It would look something like:

    # Dockerfile
    FROM node:latest AS base
    RUN apt-get update && apt-get install -y 'ffmpeg'
    
    FROM base AS server
    WORKDIR /srv/app
    COPY ./server/package*.json ./
    RUN npm install
    COPY ./server .
    RUN npm run build
    
    FROM base AS client
    WORKDIR /srv/app
    COPY ./client/package*.json ./
    RUN npm install
    COPY ./client .
    RUN npm run build
    
    FROM base AS production
    WORKDIR /srv/app
    RUN mkdir /public
    COPY --from=server /srv/app/dist ./
    COPY --from=client /srv/app/dist ./public
    ENV NODE_ENV=production
    EXPOSE 5000
    CMD ["node", "app.js"]
    
    
    Login or Signup to reply.
  2. @pdoherty926 was right. You have to install ffmpeg to all the images or at least the images that are using it and the production one. But in addition, you also have to change your code from:
    ffmpeg.setFfmpegPath(ffmpegPath.path);
    to
    ffmpeg.setFfmpegPath('/usr/bin/ffmpeg');

    This code might give you errors when running in your machine in dev mode but it should work when you run the docker image on EC2 Instance.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search