Docker with Node.js and Express.js - node.js

I'm trying to use docker with my node application, my Dockerfile looks like this:
RUN apt-get update
RUN apt-get -y install build-essential
RUN apt-get install -y nodejs
RUN apt-get install -y npm
ADD . /src
RUN cd /src && npm install
EXPOSE 8080
CMD ["node","/src/app.js"]
but after running docker build when npm install is running after trying to install https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz I get an error:
The command 'bin/sh -c /src && npm install' returned a non-zero code : 1
What can cause such an issue? I've already tried to install node-legacy instead of node and it didn't work

Try this:
# put this line on your code (if you are using ubuntu)
# this make a link from nodejs to node to add compatibility on ubuntu OS
RUN ln -s /usr/bin/nodejs /usr/bin/node
# set your current directory with WORKDIR
WORKDIR /src
RUN sudo npm install

Related

Docker failed to install img2pdf specifically permission denied on python3-pkg-resources

I have a docker file like this
FROM node:18
RUN apt-get update
RUN apt-get -y install img2pdf
RUN apt-get -y install dcmtk
WORKDIR /app
COPY package.json ./
RUN yarn install
RUN yarn global add pm2 -g
COPY . .
which working smoothly on my mac m1.
But when deploying it to ubuntu 22 machine,
it failed with bunch of permission denied python3-related issue
I've tried bunch of things including reiinstall python3 and python3-pkg-resources, which make my dockerfile now looks like this
FROM node:18
RUN apt-get clean
RUN apt-get update
RUN apt-get -y reinstall python3
RUN apt-get -y reinstall python3-pkg-resources
RUN apt-get -y install img2pdf
RUN apt-get -y install dcmtk
WORKDIR /app
COPY package.json ./
RUN yarn install
RUN yarn global add pm2 -g
COPY . .
now show this error
I don't have much knowledge around docker and computer CPU.
But so far my problem happens when I run the docker on intel machine. Now I move my production server using AMD vCPU. it run as local
Would be lovely if anyone have reference the reason for it. and what people could do

Deploying node.js web app along with docker

WE have a node.js web app.We have deployed it on server with docker.
Its working fine with node version 0.10.25. But right now i have decided it to run on latest version of node 6.5.0
To accomplish this i modified the docker file which is now looking like below
FROM ubuntu:14.04
RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security main' | sudo tee -a /etc/apt/sources.list
RUN sudo apt-get update
RUN sudo apt-get install linux-libc-dev curl git-core krb5-multidev libkrb5-dev -y
RUN sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN sudo apt-get install nodejs -y
RUN sudo ln -sf /usr/bin/nodejs /usr/bin/node
RUN ["/bin/bash", "-c", "node -v"]
RUN sudo npm cache clean
RUN sudo npm install -g bower -y
RUN sudo npm install -g gulp -y
#RUN sudo npm install -g node-sass
#RUN sudo npm install -g eslint -y
#RUN sudo npm install -g htmllint -y
RUN cd /root; git clone -b masterclone https://consultancy:Admin23#github.com/newapp/web.git
RUN cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod
EXPOSE 8000
CMD cd /root/web; NODE_ENV=production node server.js
Everything went fine except the below line which i guess causing the problem
"The command '/bin/sh -c cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod' returned a non-zero code: 1"
Use the official node image. Here a example file.
FROM node:6.5
# Enviroment variables
ENV NPM_CONFIG_LOGLEVEL warn
ENV USER node
ENV HOMEDIR /data
# add user node and change dir working dir
RUN useradd -ms /bin/bash ${USER}
RUN mkdir -p ${HOMEDIR}
WORKDIR ${HOMEDIR}
# install all dependencies
COPY package.json ./
RUN npm install --production
# add node content
COPY . .
USER node
EXPOSE 8000
CMD ["npm", "start"]
It's probably simpler to base your file off of the official NodeJS image. For v6.5, that means that FROM ubuntu:14.04 becomes FROM node:6.5.
Also, instead of doing RUN cd /root/web over and over, you might want to change the working directory with WORKDIR /root/web.

gulp not running on Docker ubuntu

I'm trying to use gulp to start a webpack compiler in a docker environment. Wheneever I try to run the command (in ssh, the Dockerfile, or the Procfile) it fails with error code 1 and prints nothing.
I checked and gulp is installed in node_packages, but when I run it from node_packages/.bin I get the same response. Running "npm" works, but running "node" appears not to work either.
Does anyone know what is going wrong?
Dockerfile
FROM quay.io/aptible/ubuntu:14.04
# Basic dependencies
RUN apt-install build-essential python-dev python-setuptools
RUN apt-install libxml2-dev libxslt1-dev python-dev
# PostgreSQL dev headers and client (uncomment if you use PostgreSQL)
# RUN apt-install libpq-dev postgresql-client-9.3 postgresql-contrib-9.3
# MySQL dev headers (uncomment if you use MySQL)
RUN apt-install libmysqlclient-dev
RUN easy_install pip
RUN apt-install node
RUN apt-install npm
# Add requirements.txt and package.json ONLY, then run pip install, so that Docker cache won't
# bust when changes are made to other repo files
ADD requirements.txt /app/
ADD package.json /app/
WORKDIR /app
RUN pip install -r requirements.txt
RUN npm install
# Add repo contents to image
ADD . /app/
# RUN npm install -g gulp
# RUN gulp webpack:dev
#django environment variables
# ENV DATABASE_URL xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# ENV SECRET_KEY xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# ENV DJANGO_SETTINGS_MODULE xxxxxxxxxxxxx
ENV PORT 3000
EXPOSE 3000
procfile
web: sudo node_modules/.bin/gulp webpack:dev && sudo python app/manage.py runserver 0.0.0.0:$PORT
Change these lines
RUN apt-install build-essential python-dev python-setuptools
...
RUN apt-install node
RUN apt-install npm
to these:
RUN apt-install build-essential curl python-dev python-setuptools
...
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
RUN apt-get install -y nodejs
You'll note we added curl to your tool installation and we're grabbing the node ppa, then installing it. This is going to give you the more current version of node on that branch. It will also come with npm, you do not need to install that separately.
Uncomment this line, as you want gulp to be a global install
# RUN npm install -g gulp
Correspondingly, in your proc file - use the global gulp

Whois with NodeJS Docker Image

I'm trying to get Whois working in NodeJS on a Dockerfile. I'm using Whois-UX (which just spawns a whois process with the whois linux command. I'm using the "node:argon" docker image, but it doesn't have whois installed. There doesn't seem to be a way to apt-get install whois inside the image either.
I then tried to use "ubuntu:12.04", but I'm having trouble running the app with it. Here is my Dockerfile:
FROM ubuntu:12.04
WORKDIR /srv
ADD . /srv
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs git git-core whois
RUN npm install
CMD ["node /srv/server.js"]
So, there are two possible solutions that I don't know how to solve. Figure out how to get whois on the node:argon image, or get the ubuntu docker image to work. I'd rather get whois on node:argon, because of optimizations for NodeJS, but as long as it works, it'll do.
Thanks for the help!
Whelp. I got it.
I forgot to apt-get update before I apt-get installed whois, so it didn't show the repository as being up.
FROM node:argon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN apt-get update
RUN apt-get install whois
RUN npm install bower -g
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
RUN bower install --allow-root
CMD ["npm", "start"]
^ This worked.

Issue running Gulp on Docker

I have the following Dockerfile
FROM debian:jessie
MAINTAINER Ewan Valentine <ewan#theladbible.com>
WORKDIR /tmp
RUN apt-get update -y && \
apt-get install -y \
curl
RUN curl --silent --location https://deb.nodesource.com/setup_0.12 | bash -
RUN apt-get install --yes nodejs
VOLUME ["/var/www/admin/src"]
RUN mkdir -p /var/www/admin/src
WORKDIR /var/www/admin/src
RUN npm install -g gulp
ENTRYPOINT ["gulp"]
However, when I run $ docker-compose run gulp I get the following error:
[10:47:49] Local gulp not found in /var/www/admin/src
[10:47:49] Try running: npm install gulp
I'm using docker-compose and this container is linked to a volume where the source code is kept, which all runs fine otherwise.
I was liking to the wrong volume! Sorted now.

Resources