Node on Linux thinks its out of date - node.js

I have a couple of Discord bots running on a VPS (Ubuntu) and I am using Docker to deploy them into containers. Both of these bots are running fine, so I am trying to launch a third one for something else. I have set it up the exact same way, however when I try and run the container, the bot logs into Discord, but then this error pops up and the app stops.
Your node version is currently 12.20.0
Please update it to a version >= 14.x.x from https://nodejs.org/
My other apps are running fine on version 12.20.0 so I am not sure what the issue is. If I have to update I will, but I don't know how to update Node on Linux.
This is the contents of my Dockerfile:
FROM node:12.20.0
# Create the directory!
RUN mkdir -p /usr/src/bot
WORKDIR /usr/src/bot
# Copy and Install our bot
COPY package.json /usr/src/bot
RUN npm install
# Our precious bot
COPY . /usr/src/bot
# Start me!
CMD ["node", "index.js"]

Related

docker container (node server) stops with err=132

my first docker project was built on a Mac.
It runs perfectly there, so I tried to transfer that to my Synology NAS running in the docker engine there.
Unfortunately, the container always stops with Error Code = 132.
I tried everything, pulling from within the docker GUI and running the container from there, but also directly from the cli (ssh). Always the same!
Any Idea?
This is my Dockerfile:
FROM node:16.13.0-alpine
USER node
WORKDIR /home/node
ADD --chown=node:node . /home/node
RUN npm install
CMD ["node","myApp.js"]

Unable to run (Linux container) or create image (Windows container) a Gatsby React site (win binaries error, matching manifest error) through Docker

I have my website wrapped up and wanted to containerize it for experience as I've never used Docker before. It's built on Gatsby. I did a fresh install of Docker and am running into two issues:
If I try to create an image in a Linux container, it seems to work, but I can't actually run it. I get the following error: "Error in "/app/node_modules/gatsby-transformer-sharp/gatsby-node.js": 'win32-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linuxmusl-x64' platform."
I tried the above, uninstalling and reinstalling sharp in my project to no avail.I'm not even using sharp nor do I know what it is, though.
If I switch to Windows containers, I can't even create an image as I get the following:
"no matching manifest for windows/amd64 10.0.18363 in the manifest list entries"
My Dockerfile is as follows:
FROM node:13.12.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
RUN npm install react-scripts#3.4.1 -g --silent
# add app
COPY . ./
# start app
CMD ["npm", "start"]
and my .dockerignore contains
node_modules
build
Dockerfile
Dockerfile.prod
.git
Things I've tried:
This tutorial > https://mherman.org/blog/dockerizing-a-react-app/ (Where I got the Dockerfile text)
This tutorial >https://www.robinwieruch.de/docker-create-react-app-development (And its Dockerfile at one point)
Changing the FROM for node: to 14.4.0, 14, with or without -alpine.
Uninstalling and re-installing sharp
Uninstalling sharp entirely and trying to run it that way (I still get the sharp error for some reason)
Reading the documentation. Which for whatever reason only tells you how to launch a default application (such as create-react-app) or one pulled from somewhere, but not how to do so for our own website.
Thanks

Why I can't install node_module with docker-sompose run command

I have a express application. And I use the docker-compose to run it. To run my app I use command:
docker-compsoe up
If I run it at first time and don't have any node_modules - I have an error in terminal, sth like "The module 'express' not found, please install it and try again...". So, I just open one more terminal, and run next command:
docker-compose exec backend npm i
Modules are installed for a few seconds. And and my app start working in the previous terminal. I allways use this method, but now I found command run for docker-compose. It allows you to exec some command in container, when it is not raised. So I wanted to try this command and I deleted ./node_modules directory, stop all containers, close all terminals, open terminal and run command:
docker-compose run backend npm i
Modules started to install, I wait for about 10 minutes but it is stops in the middle. I don't understand why? If I try up and npm i in second terminal it works, but with command run - not. What I do wrong?
You should not install your node modules in a running container. Instead, you shoud install it in your image via your Docker file and then run it via docker or docker-compose.
Your Dockerfile should look like something like this:
FROM node:10 # or the version of node you are using
WORKDIR /usr/src/app #replace this with your app code path
COPY package.json /usr/src/app
RUN npm install
COPY app-code/ /usr/src/app/app-code # again, use your own path
EXPOSE 3000
CMD ["npm", "start"]
You have to run npm install from your dockerfile and not copy your development node folder because the environment from the container may differ from your development environment.
Then you can just run it from your docker-compose file.

Can't find module error when building docker for NodeJS app

I wrote a DockerFile for a node application. This is the docker file:
FROM node:10.15.0
COPY frontend/ frontend/
WORKDIR frontend/
RUN npm install
RUN npm start
When I try to build this Dockerfile, I get this error: ERROR in ./app/main.js Module not found: Error: Can't resolve './ResetPwd' in '/frontend/app'
So I added RUN ls & RUN ls /app in Dockerfile. Both of the files are there! I'm not familiar with NodeJS and it's build process at all. Can anybody help me with this?
Point: I'm not sure if it helps or not, but I'm using Webpack too.
The problem was that our front-end developer considered that node imports are case insensitive and he was using windows. I tried to run Dockerfile on mac and that's why it couldn't find the modules. Module name was resetPass!
This question saved me!
hope this helps somebody else.
I have an angular app and I was trying to containerize it using docker.
I build the app on a windows machine. and I was trying to build it inside a linux container.
the app was building fine on my windows machine and failing with the following error in the docker environment:
ERROR in folder1/folder2/name.component.ts: - error TS2307: Cannot find module '../../../folder1/File.name'.
import { Interface1} from '../../../folder1/File.name';
Cannot find module '../../../node_modules/rxjs/Observable.d.ts'.
import { Observable } from 'rxjs/observable';
it was driving me nuts.
I saw this question and at first did not think that it was what was going on. the next day I decided to build the same app in a linux environment just to make sure. Used WSL 2 and boom:
the real problem!
ERROR in error TS1149: File name '/../../node_modules/rxjs/observable.d.ts' differs from already included file name '/../../node_modules/rxjs/Observable.d.ts' only in casing.
6 import { Observable } from 'rxjs/observable';
SO it was a casing issue. I corrected the casing and it builds fine!
I cant say if this will work for sure since I don't know if npm start actually triggers webpack, but if it doesn't you'll have to add an extra RUN line after the COPY frontend / line
There are a few issues here, try using this docker file instead
FROM node:10.15.0
# Copy dependency files and install packages
WORKDIR frontend
COPY frontend/package.* .
RUN npm install
# Copy src down and other stuff
COPY frontend /
# cd to the file with the package.json
WORKDIR /appDir/frontend
# Command that executes when container starts up
CMD ["npm", "start"]
Make sure that you also update your .dockerignore to include node_modules. You'll have to build and run the container with the following commands.
docker build -t frontendApp .
docker run -p 8080:8080 frontendApp
The -p and 8080:8080 have to do with exposing internal ports to the outside world so you can view it in a browser, just change it to whatever port web pack is using to display your stuff.
I had to rebuild the disruptive package, like in this issue for node-sass
The command would be npm rebuild <package-name>
For me, this was npm rebuild node-sass

How to dockerize React App on Windows Containers

I have a React app that I would like to Dockerize for Windows containers. this my Dockerfile:
FROM stefanscherer/node-windows
# Override the base log level (info).
ENV NPM_CONFIG_LOGLEVEL warn
# Expose port for service
EXPOSE 80
# Install and configure `serve`.
RUN npm install -g serve
# Copy source code to image
COPY . .
# Install dependencies
RUN npm install
# Build app and start server from script
CMD [ "npm", "start" ]
The image is successfully built, but when I try to run it I get this error:
Error response from daemon: container 3b4b9e2bab346bbd95b9dc144429026c1abbe7f4d088f1f10d4c959364f50e9e encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: {"CommandLine":"npm start","WorkingDirectory":"C:\\","Environment":{"NPM_CONFIG_LOGLEVEL":"warn"},"CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.
I am new with Docker so I not sure if I am missing something. Any ideas?
This error probabily is because the image base is nanoserver in this case, and then the react-scripts don't works well. Also the docker images from stefanscherer/node-windows arn't updates (the latest versions of NodeJs in these images are 12.x).
Because this, I made one new docker image with some LTS versions as 14.19.0, 16.17.0 for example.
The docker image is henriqueholtz/node-win, where the tags are the NodeJs versions.
Note: For now, the NodeJs don't have official image to windows container.
In the README in docker hub, you can see one example and the links to some articles with more examples.
See some articles with examples:
How to run ReactJs app on Windows container
How to execute windows container with NodeJs
Below one example to run your create-react-app, for example (obviously, you must change the volume to your folder - use powershell):
docker run -t -p 3000:3000 --name=my-own-cra-windows-container -v C:\Projects\my-own-cra\:C:\app\ henriqueholtz/node-win:16.17.0 cmd /c "npm -v & node -v & npm start"

Resources