NodeJS Bluez Ubuntu Dockerfile Error - node.js

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.

Related

docker file error for rm: unrecognized option '--silent'

trying to build a docker file using gcloud command
gcloud --project $PROJECT builds submit --config=cloudbuild.yaml
--substitutions=_PROJECT_ID=$PROJECT,_REPOSITORY="gitlab-runner",_IMAGE="cloudcicd:latest" .
and my docker file looks like this
FROM python:latest
# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
#Versions
#ENV HELM_VERSION=v3.6.3
ENV KUBECTL_VERSION=v1.20.9
ENV MAVEN_OPTS="-Djavax.net.ssl.trustStore=/cicd/assets/truststore.jks"
ENV TERRAFORM_VERSION=1.2.0
ENV GOLANG_VERSION=1.18.6
ENV TERRAGRUNT_VERSION=v0.38.7
#Copy python requirements file
COPY requirements.txt /tmp/pip-tmp/
# Makes the Ansible directories
RUN mkdir /etc/ansible /ansible
RUN mkdir ~/.ssh
# Configure apt and install python packages
RUN apt-get update -y -q \
&& apt-get upgrade -y -q \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
&& apt-get install -y --no-install-recommends apt-utils \
&& apt-get -y install ca-certificates software-properties-common build-essential curl git gettext-base maven sshpass krb5-user \
&& pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
&& apt-get -y install jq \
&& rm -rf /tmp/pip-tmp \
#Install helm
#RUN wget https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz \
#&& tar -zxvf helm-${HELM_VERSION}-linux-amd64.tar.gz \
#&& mv linux-amd64/helm /usr/local/bin/helm
#Install kubectl
RUN curl --silent https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl --output /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl
#Install Docker CLI
RUN curl -sSL https://get.docker.com/ | sh \
&& curl -L "https://github.com/docker/compose/releases/download/2.11.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose
#Install AWS CLI
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install
#Copy Assets
RUN mkdir -p /cicd
COPY assets /cicd
#Install helm plugins
#RUN helm plugin install /cicd/helm-nexus-push
# Downloading gcloud package
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
# Installing the package
RUN mkdir -p /usr/local/gcloud \
&& tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz \
&& /usr/local/gcloud/google-cloud-sdk/install.sh
# Adding the package path to local
ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
RUN cd /tmp && \
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin && \
rm -rf /tmp/*
RUN cd /tmp && \
wget https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz && \
tar -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz -C /usr/local && \
rm -rf /tmp/*
RUN cd /tmp && \
wget https://github.com/gruntwork-io/terragrunt/releases/download/${TERRAGRUNT_VERSION}/terragrunt_linux_amd64 && \
mv terragrunt_linux_amd64 /usr/local/bin/terragrunt && \
chmod +x /usr/local/bin/terragrunt && \
rm -rf /tmp/*
RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
ENV GOPATH=/usr/local/go
ENV PATH=/usr/local/go/bin:$PATH
ENV CGO_ENABLED=0
RUN go version
RUN terraform --version
RUN terragrunt --version
RUN ansible --version
CMD bash
and I get the following error
Reading state information...
The following additional packages will be installed:
libjq1 libonig5
The following NEW packages will be installed:
jq libjq1 libonig5
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 384 kB of archives.
After this operation, 1148 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 libonig5 amd64 6.9.6-1.1 [185 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 libjq1 amd64 1.6-2.1 [135 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 jq amd64 1.6-2.1 [64.9 kB]
Fetched 384 kB in 0s (1621 kB/s)
Selecting previously unselected package libonig5:amd64.
(Reading database ... 28446 files and directories currently installed.)
Preparing to unpack .../libonig5_6.9.6-1.1_amd64.deb ...
Unpacking libonig5:amd64 (6.9.6-1.1) ...
Selecting previously unselected package libjq1:amd64.
Preparing to unpack .../libjq1_1.6-2.1_amd64.deb ...
Unpacking libjq1:amd64 (1.6-2.1) ...
Selecting previously unselected package jq.
Preparing to unpack .../archives/jq_1.6-2.1_amd64.deb ...
Unpacking jq (1.6-2.1) ...
Setting up libonig5:amd64 (6.9.6-1.1) ...
Setting up libjq1:amd64 (1.6-2.1) ...
Setting up jq (1.6-2.1) ...
Processing triggers for libc-bin (2.31-13+deb11u4) ...
rm: unrecognized option '--silent'
Try 'rm --help' for more information.
The command '/bin/sh -c apt-get update -y -q && apt-get upgrade -y -q && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 && apt-get install -y --no-install-recommends apt-utils && apt-get -y install ca-certificates software-properties-common build-essential curl git gettext-base maven sshpass krb5-user && pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt && apt-get -y install jq && rm -rf /tmp/pip-tmp RUN curl --silent https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl --output /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BUILD FAILURE: Build step failure: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
ERROR: (gcloud.builds.submit) build 46bc93d2-9bbf-4de2-96db-8312f9b06843 completed with status "FAILURE"
im trying to push the docker file google artifact registry

Docker image erorr bin not found after npm installation

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.

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

./autogen.sh gives : invalid option

I want to add libcrafter file in cpp file which is provided from https://github.com/pellegre/libcrafter In that they provide steps
cd libcrafter/libcrafter
$ ./autogen.sh
$ make
$ sudo make install
$ sudo ldconfig
But when I run command it gives invalid option
I have already installed
sudo apt-get install autoconf libtool
sudo apt-get install libpcap0.8 libpcap0.8-dev
#!/bin/sh -e
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.
autoreconf --force --install --verbose "$srcdir"
test -n "$NOCONFIGURE" || "$srcdir/configure" "$#"
Error:
libcrafter$ sudo ./autogen.sh
[sudo] password for altaf: : invalid option

Bash string manipulation works differently in shell than .sh file?

I have a script to get and setup the latest NodeJS on my .deb system:
echo "Downloading, building and installing latest NodeJS"
sudo apt-get install python g++ make checkinstall
mkdir /tmp/node_build && cd $_
curl -O "http://nodejs.org/dist/node-latest.tar.gz"
tar xf node-latest.tar.gz && cd node-v*
NODE_VERSION="${PWD#*v}"
#NODE_VERSION=python -c "print '$PWD'.split('-')[-1][1:]"
echo "Installing NodeJS" $NODE_VERSION
./configure
sudo checkinstall -y --install=no --pkgversion NODE_VERSION
sudo dpkg -i node_$NODE_VERSION
Unfortunately it doesn't work; as the echo line outputs:
Installing NodeJS i8/dir-where-runnning-script-from/node-v0.10.24
It does work from the shell though:
$ cd /tmp/node_build/node-v0.10.24 && echo "${PWD#*v}"
0.10.24
Is there another "v" in the path, like right before the "i8/"? #*v will remove through the first "v" in the variable; I'm pretty sure you want ##*v which'll remove through the last "v" in the variable. (Technically, # removes the shortest matching prefix, and ## removes the longest match). Thus:
NODE_VERSION="${PWD##*v}"
Should work.
Try this
sudo checkinstall -y --install=no --pkgversion "${NODE_VERSION##*v}"

Resources