Docker: an error happened: ffmpeg exited with code 127 - node.js

As I mentioned above, when I run the container, I get an error. When I run it normally, it works, there is no problem.
my container run code: docker run --rm -i -t -p 8080:4444 9fa71c8ca9ba
the error i got;
an error happened: ffmpeg exited with code 127
APP.JS
https://pastebin.ubuntu.com/p/znCRWz2rgx/
Dockerfile:
FROM node:10
COPY . /app
WORKDIR /app
RUN npm install
RUN npm install fluent-ffmpeg
RUN npm install os
RUN npm install express
RUN npm install --save #google-cloud/text-to-speech
RUN npm install --save #google-cloud/translate
RUN export GOOGLE_APPLICATION_CREDENTIALS="dogwood-cipher-307314-4074350f02b8.json"
CMD ["node", "app.js"]

Related

Node.js service Timeout issues

The Node.js API service hosted on AWS times out at intervals and crashes the server. When I checked Cloudwatch logs, I saw this error come up often.
npm ERR! path /app
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c -- npm run build && node dist/server.js
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-11-11T11_54_06_397Z-debug-0.log
Here's my docker file
#!/bin/sh
FROM node:16-bullseye-slim
RUN apt-get update; \
apt-get install -y python3; \
apt-get install -y python2 make; \
apt-get install -y g++; \
ln -s /usr/bin/python2.7 /usr/bin/python;
ARG app_env
ARG DOPPLER_TOKEN
ARG DOPPLER_PROJECT
ARG DOPPLER_CONFIG
ENV NODE_ENV=${app_env}
ENV DOPPLER_TOKEN=${DOPPLER_TOKEN}
ENV DOPPLER_PROJECT=${DOPPLER_PROJECT}
ENV DOPPLER_CONFIG=${DOPPLER_CONFIG}
WORKDIR /app
COPY package*.json ./
RUN npm install
RUN npm ci --only=production
COPY . .
CMD ["npm", "run", "start:server"]
EXPOSE 3000
My package.json file start script
"start:server": "npm run build && node dist/server.js"
I'm using Node version: v16.13.2
Npm version: 8.19.0
Not sure the cause of this issue.

failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 1

I'm really new to Docker and would like to create a container that has all my angular website and its dependencies in it. I read some data and how-to's to do it but I keep struggling.
Here is my Dockerfile:
FROM node:latest AS build
WORKDIR /usr/src/app
COPY package.json ./
COPY package-lock.json ./
RUN npm cache clean --force
RUN rm -rf node_modules && rm ./package-lock.json
# RUN npm install -g npm#8.5.2
RUN npm install
COPY . .
RUN npm install -g #angular/cli
RUN chown -R $USER /usr/local/lib/node_modules
RUN npm run build
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/app/dist/demo2 /usr/share/nginx/html
EXPOSE 80

Docker node Error: 'darwin-x64' binaries cannot be used on the 'linux-x64' platform

I am trying to run a container based on my app image by using docker and i getting the next error:
/app/node_modules/sharp/lib/libvips.js:68
throw new Error('${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the '${currentPlatformId}' platform.);
Error: 'darwin-x64' binaries cannot be used on the 'linux-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linux-x64' platform.
My Dockerfile:
FROM node:10.20.1
WORKDIR /app
COPY package.json .
RUN npm install -g node-gyp
RUN npm install
EXPOSE 8080
CMD [ "npm", "start" ]
I tryied to add the next Commands to my Dockerfile but i am getting the same error:
Second attempt Dockerfile:
FROM node:10.20.1
WORKDIR /app
COPY package.json .
RUN npm install -g node-gyp
RUN rm -rf node_modules/sharp
RUN npm install --arch=x64 --platform=linux --target=8.10.0 sharp
EXPOSE 8080
CMD [ "npm", "start" ]
The docker command I using locally on my mac in order to run that container is:
docker run -d -p 8080:8080 --env-file ./.env --name server-dev-1 server:1
Any ideas?

Copy output of npm install to docker container

I dockerized node.js and all works fine
Dockerfile:
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
EXPOSE 9000
CMD ["npm", "run", "dev"]
I'm trying to run npm install outside Dockerfile and to copy content of npm install to docker container
On docker host i ran
npm install --prefix /opt/npm/ -g
Folder /opt/npm/lib/node_modules/ui is created. In that folder there are bunch json files and folder node_modules.Dockerfile is in that foler.Now, in Dockerfile i skipped npm install and just copied content of /opt/npm/lib/node_modules/ui to docker container.
Modified Dockerfile
FROM node:alpine
WORKDIR '/app'
COPY . .
EXPOSE 9000
Built image from Dockerfile sucessfully, but when trying to run container from that image
docker run -p 9000:4200 pm
> ui#0.0.0 dev /app
> ng serve --host 0.0.0.0 --proxy-config src/proxy.conf.json
sh: ng: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! ui#0.0.0 dev: `ng serve --host 0.0.0.0 --proxy-config src/proxy.conf.json`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the ui#0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Is it possible to run npm install outside docker container ?
When dockerizing any application you should always compile and install dependencies in the docker container.
Your Docker file start form node:alpine. this means that when you install an npm package that needs compilation outside (your OS) the alpine OS won't be able to use this.
Best practice is to always build your application on the same OS. That's way docker introduce build container.
# Dockerfile
FROM node:12.13-alpine As build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
FROM node:12.13-alpine as production
WORKDIR /usr/src/app
COPY ./ ./ # copy static files
COPY --from=build /usr/src/app/node_modules ./. # Copy node_modules from build container
EXPOSE 3000
CMD ["node", "main.js"]
# .dockerignore
node_modules
Dockerfile
Try to fit this to your environment

Installing fresh react app with dockerfile

I'm trying to run a fresh installation of React using a Dockerfile.
FROM node:12.14-alpine
RUN mkdir /app
WORKDIR /app
RUN npm install -g nodemon \
npx create-react-app .
COPY package.json package.json
RUN npm install --silent
COPY . .
CMD [ "node", "start" ]
My root folder is empty so no package.json file exists etc. When I run docker-compose up --build I get the following error which indicates that's failing on npx create-react-app .
Step 5/9 : RUN npm install -g nodemon npx create-react-app .
---> Running in c4878af5f94d
npm ERR! code ENOLOCAL
npm ERR! Could not install from "" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-02-18T12_55_14_899Z-debug.log
ERROR: Service 'react' failed to build: The command '/bin/sh -c npm install -g nodemon npx create-react-app .' returned a non-zero code: 1
Any ideas what I'm doing wrong? I'm not having node or npm installed nativelly so all needs t run through docker
You need to delete the . at the end of the RUN :
RUN npm install -g nodemon \
npx \
create-react-app
You forgot "&&" at the beginning line 7
FROM node:12.14-alpine
RUN mkdir /app
WORKDIR /app
RUN npm install -g nodemon \
&& npx create-react-app .
COPY package.json package.json
RUN npm install --silent
...
CMD [ "node", "start" ]

Resources