Docker image erorr bin not found after npm installation - node.js

I need to extend a Dockerfile and add grunt to it. I did the following:
This docker run as-is
FROM openjdk:8-jdk-slim
ARG ND=v12.13.0
RUN apt-get update && \
apt-get install --yes --no-install-recommends curl && \
NODE_H=/opt/nodejs; mkdir -p ${NODE_H} && \
curl --fail --silent --output - "http://nodejs.org/dist/${ND}/node-${ND}-linux-x64.tar.gz" \
| tar -xzv -f - -C "${NODE_H}" && \
ln -s "${NODE_H}/node-${ND}-linux-x64/bin/npm" /usr/local/bin/npm && \
ln -s "${NODE_H}/node-${ND}-linux-x64/bin/node" /usr/local/bin/node && \
ln -s "${NODE_H}/node-${ND}-linux-x64/bin/npx" /usr/local/bin/ && \
npm install grunt-cli -g
RUN grunt -v
I've put also the following which doesn't help...
ENV PATH="$PATH:/usr/local/bin"
When I run the command grunt-v I get the following error:
/bin/sh: 1: grunt: not found.
I try also to install grunt through npm install grunt -g without success. Any idea how to fix it?
grunt output from docker build
/opt/nodejs/node-v12.13.0-linux-x64/bin/grunt -> /opt/nodejs/node-v12.13.0-linux-x64/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli#1.3.2
I need the grunt command to be available in this docker image
I cannot change the docker image, i.e. form jdk...this is given
update
I've also tried with what VonC suggested but still have issue,
FROM openjdk:8-jdk-slim
ARG ND=v12.13.0
RUN apt-get update && \
apt-get install --yes --no-install-recommends curl && \
# install node
NODE_HOME=/opt/nodejs; mkdir -p ${NODE_HOME} && \
curl --fail --silent --output - "http://nodejs.org/dist/${ND}/node-${ND}-linux-x64.tar.gz" \
| tar -xzv -f - -C "${NODE_HOME}" && \
ln -s "${NODE_HOME}/node-${ND}-linux-x64/bin/node" /usr/local/bin/node && \
ln -s "${NODE_HOME}/node-${ND}-linux-x64/bin/npm" /usr/local/bin/npm && \
ln -s "${NODE_HOME}/node-${ND}-linux-x64/bin/npx" /usr/local/bin/ && \
npm install -g grunt-cli
ENV PATH="${PATH}:/usr/local/bin"
RUN ls /usr/local/bin/
RUN grunt -v
the ls command returns
docker-java-home
node
npm
npx
Any idea what is missing?

this will work:
FROM openjdk:8-jdk-slim
ARG ND=v12.13.0
RUN apt-get update && \
apt-get install --yes --no-install-recommends curl \
&& NODE_HOME=/opt/nodejs; mkdir -p ${NODE_HOME} \
&& curl --fail --silent --output - "http://nodejs.org/dist/${ND}/node-${ND}-linux-x64.tar.gz" \
| tar -xzv -f - -C "${NODE_HOME}" \
&& ln -s "${NODE_HOME}/node-${ND}-linux-x64/bin/node" /usr/local/bin/node \
&& ln -s "${NODE_HOME}/node-${ND}-linux-x64/bin/npm" /usr/local/bin/npm \
&& ln -s "${NODE_HOME}/node-${ND}-linux-x64/bin/npx" /usr/local/bin/ \
&& npm install --prefix /usr/local/ -g grunt-cli
ENV PATH="${PATH}:/usr/local/bin"
RUN ls /usr/local/bin
RUN grunt -v
using --prefix will tell npm to install grunt in /usr/local/bin
ls output:
Step 5/6 : RUN ls /usr/local/bin
---> Running in 96493743512d
docker-java-home
grunt
node
npm
npx
grunt -v output:
Step 6/6 : RUN grunt -v
---> Running in c6248c4fce6c
grunt-cli: The grunt command line interface (v1.3.2)

I've put also the following which doesn't help...
ENV PATH="$PATH:/usr/local/bin"
As illustrated here, that should be enough, also the exact syntax would be (to be sure)
ENV PATH="${PATH}:/usr/local/bin"
But:
make sure to add it just before your last RUN grunt
add a RUN ls /usr/local/bin/ to see if your install command worked
try and use the syntax npm instal -g grunt, instead of npm instal grunt -g
Another approach:
The Docker image openjdk:8-jdk-slim is based on debian:buster-slim
So try and install node through its installation script, as seen here:
# install node.js environment
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gnupg && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN curl -sL https://deb.nodesource.com/setup_${NODEJS_VERSION}.x | bash -
RUN apt-get update && \
apt-get install -y --no-install-recommends \
nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
npm install -g grunt
You can still use the same base image openjdk:8-jdk-slim, but you just extend it with a regular node installation, rather than fiddling with symbolic links.
In your case, add ENV NODEJS_VERSION 12 first.

This works
FROM openjdk:8-jdk-slim
ARG NODE_HOME=/opt/nodejs
ARG ND=v12.13.0
ENV PATH=${PATH}:${NODE_HOME}/node-${ND}-linux-x64/bin/
RUN apt-get update && \
apt-get install --yes --no-install-recommends curl && \
# install node
mkdir -p ${NODE_HOME} && \
curl --fail --silent --output - "http://nodejs.org/dist/${ND}/node-${ND}-linux-x64.tar.gz" \
| tar -xzv -f - -C "${NODE_HOME}" && \
npm install -g grunt-cli
RUN grunt -v
First, move NODE_HOME up in your dockerfile and set it as a build arg.
That way we can already set the PATH early on.
By setting the path to the node bin folder we can use all binaries in that location without manually linking each. That translates to grunt being available after installation without additional black magic.

Related

Dockerfile build fails all of a sudden

I'm trying to resolve build problems when running commands to build below dockerfile,
errors for example I get:
1.
/bin/sh: 1: /opt/conda/bin/pip: not found
The command '/bin/sh -c wget -q https://repo.continuum.io/miniconda/Miniconda3-4.2.12-Linux-x86_64.sh -O /tmp/miniconda.sh && echo 'd0c7c71cc5659e54ab51f2005a8d96f3 */tmp/miniconda.sh' | md5sum -c - && bash /tmp/miniconda.sh -f -b -p /opt/conda && /opt/conda/bin/conda install --yes -c conda-forge python=3.5 sqlalchemy tornado jinja2 traitlets requests pip pycurl nodejs configurable-http-proxy && /opt/conda/bin/pip install --upgrade pip && rm /tmp/miniconda.sh' returned a non-zero code: 127
2.
When trying to comment the problematic part we get another issue with npm such as:
/bin/sh: 1: npm: not found
Any idea what's going on here?
Dockerfile
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
FROM debian:jessie
MAINTAINER Jupyter Project <jupyter#googlegroups.com>
# install nodejs, utf8 locale, set CDN because default httpredir is unreliable
ENV DEBIAN_FRONTEND noninteractive
RUN REPO=http://cdn-fastly.deb.debian.org && \
echo "deb $REPO/debian jessie main\ndeb $REPO/debian-security jessie/updates main" > /etc/apt/sources.list && \
apt-get -y update && \
apt-get -y upgrade && \
apt-get -y install wget locales git bzip2 &&\
/usr/sbin/update-locale LANG=C.UTF-8 && \
locale-gen C.UTF-8 && \
apt-get remove -y locales && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
ENV LANG C.UTF-8
# install Python + NodeJS with conda
RUN wget -q https://repo.continuum.io/miniconda/Miniconda3-4.2.12-Linux-x86_64.sh -O /tmp/miniconda.sh && \
echo 'd0c7c71cc5659e54ab51f2005a8d96f3 */tmp/miniconda.sh' | md5sum -c - && \
bash /tmp/miniconda.sh -f -b -p /opt/conda && \
/opt/conda/bin/conda install --yes -c conda-forge \
python=3.5 sqlalchemy tornado jinja2 traitlets requests pip pycurl \
nodejs configurable-http-proxy && \
/opt/conda/bin/pip install --upgrade pip && \
rm /tmp/miniconda.sh
ENV PATH=/opt/conda/bin:$PATH
EXPOSE 8000
RUN mkdir -p /src/jupyterhub
WORKDIR /src/jupyterhub
ADD . /src/jupyterhub
RUN npm install --unsafe-perm && \
pip install . && \
rm -rf $PWD ~/.cache ~/.npm
ADD . /src/jupyterhub
LABEL org.jupyter.service="jupyterhub"
CMD ["jupyterhub"]
The latest pip package hosted by conda forge is noarch/pip-20.0.2-py_2.tar.bz2 and it has the bin folder missing hence calling /opt/conda/bin/pip will give /opt/conda/bin/pip: not found error.
I would suggest enforcing the versions of the packages to prevent updated versions causing build error, this will achieve deterministic builds in different machines which saves time on having to figure out what version change is causing the error.
In order to get pip properly, amending the Dockerfile with the below should do the trick:
RUN wget -q https://repo.continuum.io/miniconda/Miniconda3-4.2.12-Linux-x86_64.sh -O /tmp/miniconda.sh && \
echo 'd0c7c71cc5659e54ab51f2005a8d96f3 */tmp/miniconda.sh' | md5sum -c - && \
bash /tmp/miniconda.sh -f -b -p /opt/conda && \
/opt/conda/bin/conda install --yes -c conda-forge \
python=3.5 sqlalchemy tornado jinja2 traitlets requests pip=18.0=py35_1001 pycurl \
nodejs configurable-http-proxy && \
/opt/conda/bin/pip install --upgrade pip && \
rm /tmp/miniconda.sh

Forgerock - Forgeops - util - building with RHEL?

I am trying to take this Dockerfile here - https://github.com/ForgeRock/forgeops/blob/release/6.5.0/docker/util/Dockerfile
And change the old version which is Alpine linux (seen below):
FROM alpine:3.7
...
RUN apk add --update ca-certificates \
&& apk add --update -t deps curl\
&& curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl \
&& apk del --purge deps \
&& apk add --update jq su-exec unzip curl bash openldap-clients \
&& rm /var/cache/apk/* \
&& mkdir -p $FORGEROCK_HOME \
&& addgroup -g 11111 forgerock \
&& adduser -s /bin/bash -h "$FORGEROCK_HOME" -u 11111 -D -G forgerock forgerock
To change it to run off of RHEL 7 (my changes below)
FROM ubi7-stigd:7.6
...
# Install epel, so we can install jq later
RUN rpm --import http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 \
&& yum install -y --disableplugin=subscription-manager https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# Install other stuff
RUN yum -y --disableplugin=subscription-manager update \
&& yum install -y --disableplugin=subscription-manager jq su-exec unzip curl bash openldap-clients ca-certificates deps \
&& curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl \
&& mkdir -p $FORGEROCK_HOME \
&& groupadd -g 11111 forgerock \
&& useradd -m -s /bin/bash -d "$FORGEROCK_HOME" -u 11111 -g forgerock -G root forgerock
The container builds just fine (although it complains about not being able to find "su-exec" and "deps"). But when I upload this image to my OpenShift and run it via an OpenAM pod, the container fails to start, timing out after 10 minutes. The events show that the container started, and logs only show 2 lines, saying it timed out after 10 minutes.
Anyone know what the issue might be?
I needed to install the "nc" package, as one of the .sh files uses nc.

NodeJS Bluez Ubuntu Dockerfile Error

I have a docker file that is supposed to build a container to run a simple Bluetooth scanning program written with nodejs that depends on bluez, Ubuntu and Noble.js but when I run it I get the following error that stops me from building the container when running a docker build -t. Here is the Dockerfile. And the error,
48 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
wget: invalid option -- 'f'
wget: invalid option -- 's'
Usage: wget [OPTION]... [URL]...
Try `wget --help' for more options.
The command '/bin/sh -c apt-get update && apt-get install -y vim python3 python3-dev python3-pip python3-virtualenv python3-wheel gcc build-essential libglib2.0-dev libbluetooth-dev libboost-python-dev git libdbus-1-dev libudev-dev libical-dev libreadline-dev wget curl --no-install-recommends && wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.49.tar.xz tar -xf bluez-5.49.tar.xz cd bluez-5.49 ./configure make make install curl -sL https://deb.nodesource.com/setup_9.x -o nodesource_setup.sh bash nodesource_setup.sh apt-get update && apt-get install -y apt-get install nodejs ln -s /usr/bin/nodejs /usr/bin/node rm -rf /var/lib/apt/lists/*' returned a non-zero code: 2
Look at the following section, particularly where tar is first called:
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.49.tar.xz tar -xf bluez-5.49.tar.xz cd bluez-5.49 ./configure make make install curl -sL https://deb.nodesource.com/setup_9.x -o nodesource_setup.sh bash nodesource_setup.sh apt-get update && apt-get install -y apt-get install nodejs ln -s /usr/bin/nodejs /usr/bin/node rm -rf /var/lib/apt/lists/*
When executing multiple commands in succession on a single line, you need to separate those commands with an operator like &&.
The && operator will run a command, but only if the first succeeds
The || operator will run a command, but only if the first fails
The ; operator will run a command, regardless if the first succeeds or fails
In addition you have a stray apt-get install in your command, most likely a copy/paste error. The section above should look like this:
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.49.tar.xz && tar -xf bluez-5.49.tar.xz && cd bluez-5.49 && ./configure && make && make install && curl -sL https://deb.nodesource.com/setup_9.x -o nodesource_setup.sh && bash nodesource_setup.sh && apt-get update && apt-get install -y nodejs && ln -s /usr/bin/nodejs /usr/bin/node && rm -rf /var/lib/apt/lists/*
As an additional note, the ln -s /usr/bin/nodejs /usr/bin/node is probably unnecessary and will cause an error, as the nodejs package already appears to create /usr/bin/node.

installing nodejs before building spring boot app

So i am building a spring boot app with angular 4 front end and i need to automate the build and i am using AWS developer suite for that
i already created the pipeline that watch my repo changes and i have this buildspec.yml with following configuration
version: 0.2
phases:
install:
commands:
- sudo apt-add-repository ppa:chris-lea/node.js
- sudo apt-get -y update
- sudo apt-get -y install nodejs=7.9.0
- node -v
- sudo npm install -g #angular/cli
pre_build:
commands:
- sudo cd src/main/frontend
- sudo npm install && sudo npm run deploy-dev
- sudo cd .. && sudo cd .. && sudo cd..
build:
commands:
- echo Build started on `date`
- mvn clean install
post_build:
commands:
- mv target/ROOT.war.original ROOT.war
artifacts:
files:
- '**/*'
base-directory: 'target/ROOT'
and it's basically install nodejs and then install angular-cli to build Angular 4 after that move all dist/* to /resources/public in the spring boot and then run maven build.
my problem is I couldn't install node i tried many ways none of them worked for me , can any one help me with a second eye or have any experience with this ?
my build environment for AWS codebuild is Java8
Well , i ended up installing nodejs v7.0.0 through bash script
i used below script
set -ex \
&& for key in \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
FD3A5288F042B6850C66B31F09FE44734EB7990E \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
; do \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys"$key"; \
done
sudo apt-get update
wget "https://nodejs.org/download/release/v7.0.0/node-v7.0.0-linux-
x64.tar.gz" -O node-v7.0.0-linux-x64.tar.gz \
&& wget "https://nodejs.org/download/release/v7.0.0/SHASUMS256.txt.asc" -O SHASUMS256.txt.asc \
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
&& grep " node-v7.0.0-linux-x64.tar.gz\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xzf "node-v7.0.0-linux-x64.tar.gz" -C /usr/local --strip-components=1 \
&& rm "node-v7.0.0-linux-x64.tar.gz" SHASUMS256.txt.asc SHASUMS256.txt \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
&& rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*
basically this script will download and install nodejs v7.0.0 for you
which i took it from here
Hi , future struggler i left some dessert for you 3>

Docker, running NVM script in a new bash shell

I have the following in my Dockerfile:
run apt-get update; \
apt-get install -y curl && \
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
Following this line of code, I need to run a command in a new bash shell so that the environment variable set from the NVM script are used.
I have tired the following to install Nodejs and it does not work:
run ["/bin/bash", "-c", "nvm install 8.7.0"]
What can I do?
It's better to use a Dockerhub repo and use it in your Dockerfile.
You can check this repositorie or this link for more repositories, please read description before choosing a repositorie.
So for example, you can add the code line below in your Dockerfile it will pull the nvm image and install it then add your app instructions.
FROM livingdocs/nvm
Or you can read their Dockerfile and use the command they used it to install nvm
ADD ./.nvmrc /app/.nvmrc
RUN bash -c '. /usr/share/nvm/nvm.sh && cd /app && nvm install && nvm alias default'
if it didn't put this one from another repositorie:
RUN sudo apt-get update && \
sudo apt-get install -y build-essential libssl-dev libmysqlclient-dev && \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl --location https://raw.github.com/creationix/nvm/master/install.sh | sh && \
sudo /bin/bash -c "echo \"[[ -s \$HOME/.nvm/nvm.sh ]] && . \$HOME/.nvm/nvm.sh\" >> /etc/profile.d/npm.sh" && \
echo "[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh" >> $HOME/.bashrc

Resources