Workers for phantomJs fail to start in a Docker container - node.js

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.

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

/bin/sh: npm: command not found

I am creating a docker image for stf.installing nodejs directly using apt-get install nodejs,had many issues.So i decided to go the nvm way.but after installation RUN npm install fails
I am building the docker image with su username docker build ..
make sure apt is up to date
RUN apt-get update --fix-missing
RUN apt-get install -y curl
RUN sudo apt-get install -y build-essential libssl-dev
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 6
# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash \
&& source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
#WORKDIR /usr/app
# Install app dependencies
RUN npm install
and the output
=> Downloading nvm from git to '/usr/local/nvm'
=> Cloning into '/usr/local/nvm'...
* (HEAD detached at v0.30.1)
master
=> Appending source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm
Downloading https://nodejs.org/dist/v6.13.0/node-v6.13.0-linux-x64.tar.xz...
######################################################################## 100.0%
WARNING: checksums are currently disabled for node.js v4.0 and later
Now using node v6.13.0 (npm v3.10.10)
default -> 6 (-> v6.13.0)
Now using node v6.13.0 (npm v3.10.10)
Removing intermediate container eb9cb6c46f34
---> eeef6bf9f0f1
Step 38/52 : ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
---> Running in 185bef8e530c
Removing intermediate container 185bef8e530c
---> 0e5bf7b1cfd9
Step 39/52 : ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
---> Running in 00d58493e199
Removing intermediate container 00d58493e199
---> 81ed9823020b
Step 40/52 : RUN npm install
---> Running in 1c7577133e24
/bin/sh: npm: command not found
The command '/bin/sh -c npm install' returned a non-zero code: 127
Please Help.Thanks
Ran the container and checked NPM path
root#69e513b99e68:/home/mobile/MobileFarmDocker#
echo $PATH
/usr/local/nvm/versions/node/v6.13.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root#69e513b99e68:/home/mobile/MobileFarmDocker# which npm
/usr/local/nvm/versions/node/v6.13.0/bin/npm
Your $NODE_VERSION variable has value 6 as defined in the Dockerfile (ENV NODE_VERSION 6) but it should be 6.13.0 so that the following line may work properly:
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
(mapping to /usr/local/nvm/versions/node/v6.13.0/bin)
Otherwise, you are actually generating the following (wrong) path:
/usr/local/nvm/versions/node/v6/bin

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

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