Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg install within existing Node.js docker image

I need to use ffmpeg in a Node.js application that runs in a docker container (created using docker-compose). I'm very new to Docker, and would like to know how to command Docker to install ffmpeg when creating the image.

DockerFile

FROM node:carbon
WORKDIR /usr/src/app

# where available (npm@5+)
COPY package*.json ./
RUN npm install -g nodemon
RUN npm install --only=production
COPY . .

EXPOSE 3000
CMD [ "npm", "start" ] 

package.json:

{
  "name": "radcast-apis",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
    "dev": "nodemon --inspect-brk=0.0.0.0:5858 ./bin/www"
  },
  "dependencies": {
    "audioconcat": "^0.1.3",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "express": "~4.16.0",
    "firebase-admin": "^5.12.1",
    "http-errors": "~1.6.2",
    "jade": "~1.11.0",
    "morgan": "~1.9.0"
  },
  "devDependencies": {
    "nodemon": "^1.11.0"
  }
}

docker-compose.yml:

version: "2"
services:
  web:
    volumes:
    - "./app:/src/app"
    build: .
    command: npm run dev
    ports:
    - "3000:3000"
    - "5858:5858"
like image 411
Peza Avatar asked Jun 05 '18 06:06

Peza


People also ask

Can Docker replace Git?

Sure, Git and Docker are completely different and often used both at the same time. However both have repositories and both can be used to store and deliver code. Even the commands themselves are called the same: push and pull. Docker even has image tags which resemble commits to some limited extend.

Can you use Git with Docker?

Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container.

What is the difference between GitHub and Docker?

Docker belongs to "Virtual Machine Platforms & Containers" category of the tech stack, while GitHub can be primarily classified under "Code Collaboration & Version Control". Some of the features offered by Docker are: Integrated developer tools. open, portable images.


2 Answers

ffmpeg-static will work fine, but it means that every time you change package.json, or anything above the COPY command for package.json, you'll have to wait for the npm install command to re-download the bins.

There is another method, using multi-stage builds. This method won't require re-downloading or rebuilding ffmpeg. There are prebuilt ffmpeg images at jrottenberg/ffmpeg.

For alpine, your image would look like this...

FROM jrottenberg/ffmpeg:3.3-alpine
FROM keymetrics/node:8-alpine

# copy ffmpeg bins from first image
COPY --from=0 / /

Related question: Copy ffmpeg bins in multistage docker build

like image 163
posit labs Avatar answered Sep 22 '22 14:09

posit labs


If it helps anyone, I figured out a way.

  • Use ffmpeg-static by adding the entry to package.json "ffmpeg-static": "^2.3.0", this makes the binary files available in the docker container.
  • By using ffmpeg_static = require('ffmpeg-static') and then inspecting the path property on ffmpeg_static, you can see where the binaries are in the container.
  • Add this path to an ENV variable: ENV PATH="/your/path/to/node_modules/ffmpeg-static/bin/linux/x64:${PATH}"

That worked a trick for us! The answer that saved us was an analogous use-case for firebase cloud functions - here.

like image 25
Peza Avatar answered Sep 25 '22 14:09

Peza