docker elevate user priviledges - node.js

I'm trying to sudo for a node install:
sudo npm install -g grunt
sudo npm install -g grunt-cli
sudo npm install -g bower
The commands error stating to run as an administrative user. How do I do that in the Dockerfile?
RUN npm install -g grunt
#RUN ln -s /home/dev/spikes/node-esjs-master/node_modules/grunt /usr/bin/grunt
RUN npm install -g grunt-cli
#RUN ln -s /home/dev/spikes/node-esjs-master/node_modules/grunt-cli /usr/bin/grunt-cli
RUN npm install -g bower
#RUN ln -s /home/dev/spikes/node-esjs-master/node_modules/bower /usr/bin/bower
I don't actually try to sudo in the docker commands...I have after connecting to the container but when prompted for the password I don't know it. I tried to create a sym link but couldn't get that to work. My apologies if this is basic in nature - new environments for me :-).
Thanks!

You don't need to use sudo because all commands in the dockerfile are executed as root. A sample Dockerfile to install those software (Ubuntu Thrusty as base):
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y nodejs npm
RUN npm install -g grunt
RUN npm install -g grunt-cli
RUN npm install -g bower
The same applies for the run command:
$ sudo docker run my_awesome_image whoami
root

Related

Undoing unsafe PATH changes with sudo

I needed to install a global npm package (on macos), so I ran the following command:
npm install -g <package-name>
I was given an EACCESS error, and I turned to this Stack Overflow question. I ran the following two commands (from Anirban Sanyal's answer):
sudo chown -R root:$(whoami) /usr/local/lib/node_modules/
sudo chmod -R 775 /usr/local/lib/node_modules/
I once again ran the command npm install -g <package-name>, but it threw an EACCESS error again. I then ran this command:
sudo npm install -g <package-name> --unsafe-perm=true --allow-root
which worked, and my package was installed globally.
I am wondering whether any of these commands have changed something in PATH or root permanently, and if so how I can reverse them.

How to set up Truffle and Ganache with Docker on Apple Silicon

error - node-gyp-build: Permission denied while setting up truffle and ganache with docker on Apple Silicon
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v17.9.0/lib/node_modules/truffle/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: 1: node-gyp-build: Permission denied
These are some steps i followed to install truffle with docker on my m1 Macbook.
I'll be doing it for ubuntu image container
docker run -it ubuntu
on your container execute below:
apt-get update && apt-get upgrade
apt-get install sudo build-essential python3 wget curl
Then install nvm from https://github.com/nvm-sh/nvm#install--update-script
On above link there must be these two commands but with updated versions
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
then install node and npm with:
nvm install node
node install npm
npm install npm
after executing
nvm install-latest-npm
you'll find a statement to update npm to the latest version, execute that command, which should look like, npm install -g npm#8.6.0, after that install truffle
npm install -g truffle
there will be a permission issue in executing above command for which you've to execute
sudo chown -R $(whoami) <path to node_modules directory>
Note: the above command has path to node_modules you need to find the path to your node_modules from your error. in my case it was /root/.nvm/versions/node/v17.9.0/lib/node_modules/ so i executed, sudo chown -R $(whoami) /root/.nvm/versions/node/v17.9.0/lib/node_modules/
retry npm install -g truffle
after this you should be done with installation, but you would face problems where you couldn't execute the truffle file.
for this just allow your truffle file to be executed by running:
chmod u+x <path to truffle> you may find the path to truffle with which truffle, execute as below.
chmod u+x /root/.nvm/versions/node/v17.9.0/bin/truffle
For Ganache installation:
npm install ganache --global
To your package.json add,
"scripts": {
"ganache": "ganache --wallet.seed myCustomSeed"
}
Then execute,
npm run ganache
you should be able to see output something like RPC Listening on 127.0.0.1:8545
now execute truffle console, make sure you add correct port number like above 8545 in file truffle-config.js of your code, when you use it.
now execute truffle console

npm install global in Dockerfile

Trying to install resume-cli through docker but getting some permission errors on installing resume-cli.
Dockerfile:
FROM python:3.7-slim-buster
RUN apt-get update
RUN apt-get install -y curl
SHELL ["/bin/bash", "--login", "-c"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
RUN nvm install 15.13.0
RUN npm install -g resume-cli --unsafe-perm=true --allow-root
RUN npm install -g jsonresume-theme-paper
and i run: docker build -t containernpm .
where I get Error on RUN npm install -g resume-cli --unsafe-perm=true --allow-root:
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v15.13.0/lib/node_modules/resume-cli/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! sh: 1: node: Permission denied
btw next line RUN npm install -g jsonresume-theme-paper (with -g) runs normally without permission error.
Any idea how to overpass that without removing -g on RUN npm install -g resume-cli --unsafe-perm=true --allow-root
? (by removing -g runs without error)
I can't say I know why the permissions errors are happening, but here is a Dockerfile that works.
FROM node:15.13.0-buster-slim
RUN npm install -g resume-cli
ENTRYPOINT ["resume"]
There is a related question (sh: 1: node: Permission denied) but the top-voted answer there does not work for me.

Permission denied while trying to install opencv4nodejs in Ubuntu

I was trying to install opencv4nodejs in Ubuntu-20.04 using the following command and my node version is v12.19.0
sudo npm i -g opencv4nodejs
But getting those errors
info install installing opencv version 3.4.6 into directory: /usr/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv
ERR! Error: Command failed: mkdir -p opencv
mkdir: cannot create directory ‘opencv’: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build#0.1.9 install: `node ./install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the opencv-build#0.1.9 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-10-28T06_33_21_090Z-debug.log
Running NPM install with sudo might be causing a permissions problem. You could try completely removing the node_modules directory and re-running NPM install it without sudo.
Also make sure you have permission to write to the directory you're installing in?
If it still doesn't work please follow this:
sudo npm install -g opencv4nodejs --unsafe-perm=true --allow-root
This is complete guide to install opencv4nodejs to Linux OS or Raspberry pi (Raspberry Pi OS )
configuration
01- sudo raspi-config expand file system // this is for raspberry pi
After Reboot (sudo reboot now)
02- df -h (To check expand file system)
03- sudo apt-get update && sudo apt-get upgrade -y
04- sudo passwd root // set up your root password
Reboot
To Install NodeJS
01- sudo apt-get install git -y
02- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - // replase 12 with latest nodejs (LTS) version
03- sudo apt-get install nodejs -y
04- sudo apt-get install gcc g++ make
To Install opencv4nodejs
01. sudo apt-get install cmake -y
02. sudo npm install -g node-gyp
I am using this steps for raspberry pi os
03. sudo nano /etc/dphys-swapfile
(Increase the CONF_SWAPSIZE from 100 to 1024)
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
cd to home dir..
04. mkdir opencv
05. cd opencv
06. sudo npm init -y
07. su
// Enter your setup root password
08. sudo npm install --save opencv4nodejs
09. sudo nano /etc/dphys-swapfile
(Set the CONF_SWAPSIZE back to 100)
In index.js and node_modules in same folder
const cv = require("opencv4nodejs");
In index.js and node_modules in not in same folder
const cv = require("path/opencv/node_modules/opencv4nodejs");
! you don't need to install opencv4nodejs for each folders
You can simply call that above way
Hope guys you can understand it...
Any questions feel free to ask...
Thank you

compser -v doesn't show version and composer-playground command not not found on ubuntu 16.04

I ran all the installations
npm install -g composer-cli ,
npm install -g composer-rest-server
npm install -g generator-hypeldger-composer
npm install -g yo
npm install -g composer-playground
.
These commands have executed without any errors and I was able to view them at ~/.npm-global/lib/node_modules$ but I run composer --version it is not showing the version Composer version #package_branch_alias_version# (1.0.0-beta2) 2016-03-27 16:00:34, and composer-playground: command not found.
Please do suggest if I need to setup any path manually or there is something to fix.
I would run the curl command to install composer on Ubuntu
curl -sS https://getcomposer.org/installer -o composer-setup.php

Resources