gulp not running on Docker ubuntu - node.js

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

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

Workers for phantomJs fail to start in a Docker container

I am working on Dockerizing my node app which uses highcharts-export-server and creates images in my code. When I run the created image on my local machine the workers fail to start saying
`
phantom worker 7 error - /usr/src/app/node_modules/phantomjs-
prebuilt/lib/phantom/bin/phantomjs: 1:
/usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs: Syntax error: Unterminated quoted string.
The node version I am using is 8. I have also tried logging platform and architecture using process.platform and process.arch respectively inside my running container and using those values to set in Environment variables PHANTOMJS_PLATFORM and PHANTOMJS_ARCH in my dockerfile. I have also tried to install phantomJs separately using RUN npm i -g phantomjs-prebuilt --unsafe-perm. My Docker file looks like this currently.
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
ENV PHANTOMJS_BIN "/usr/local/bin/phantomjs"
ENV PHANTOMJS_PLATFORM "linux"
ENV PHANTOMJS_ARCH "x64"
ENV ACCEPT_HIGHCHARTS_LICENSE="YES"
RUN apt-get update && \
apt-get install -y \
python3 \
python3-pip \
python3-setuptools \
groff \
less \
&& pip3 install --upgrade pip \
&& apt-get clean
RUN pip3 --no-cache-dir install --upgrade awscli
RUN npm set strict-ssl false
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
Not sure if this helps but you can give it a try:
Run npm i phantomjs-prebuilt --unsafe-perm in you app folder, i.e. without -g. This should create a folder in node_modules called "phantomjs-prebuilt".
Also, check if you have phantomjs binary file created in the following path node_modules/phantomjs-prebuilt/lib/phantom/bin/ once you run this command.

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.

Docker with Node.js and Express.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

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