Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass 'yes' response when npm installing on Dockerfile

I have a Dockerfile like below :

FROM node:latest

RUN npm install something && \
    npm install something && \
    npm install something 

I want to pass 'yes' response for all required 'yes/no' param when npm installing. Is there any way to do this?

like image 930
sam Avatar asked May 23 '18 18:05

sam


People also ask

How do I make sure npm is installed?

Test NPM. To see if NPM is installed, type npm -v in Terminal.

Why use npm CI instead of npm install?

Use npm install to install new dependencies , or to update existing dependencies (e.g. going from version 1 to version 2). Use npm ci when running in continuous integration, or if you want to install dependencies without modifying the package-lock.

What is npm INIT flag?

The -y flag when passed to NPM commands tells the generator to use the defaults instead of asking questions. npm init -y. will simply generate an empty npm project without going through an interactive process. The -y stands for yes . More about npm-init here.

Does npm install use package json?

By default, npm install will install all modules listed as dependencies in package. json .

What happens if I fail to remove npmrc from my dockerfile?

If you fail to remove your .npmrc file from your Dockerfile, it will be saved in your Docker image. It will exist on the file system of any Docker container you create from that image. Here’s a Dockerfile where we create an .npmrc file but fail to delete it after running npm install:

Can Docker build secrets be used to download private npm packages?

On February 24th, 2019 I published a follow-up post about using Docker build secrets instead of multi-stage builds. I recommend reading that post after this one! I recently completed a security audit of Docker images for a project. These images used .npmrc files ( npm config files) to download private npm packages.

What happens when you run NPM install without arguments?

Running npm install without arguments installs modules defined in the dependencies section of the package.json file. It's important that npm install is run in the same directory as the package.json file. The downloaded modules are placed in a node_modules folder in the same location as package.json.

Can someone steal my NPM token from my Docker container?

If an attacker compromised your Docker container they would not be able to steal your npm token. Unfortunately, each RUN instruction creates a separate layer (also called intermediate image) in a Docker image. Multiple layers make up a Docker image.


2 Answers

I used the following to install Angular without usage statistics sharing.

RUN echo n | npm install -g --silent @angular/cli

I think echo y should work for you

like image 92
Darth Jurassic Avatar answered Oct 22 '22 00:10

Darth Jurassic


There's the yes command specifically for this in linux:

RUN yes | npm install something && \
    npm install something && \
    yes yes | npm install something 

The first line outputs a list of "y" to the first npm install command. The yes command also takes an option of what you want it to output. So if you need to output "yes" instead of a single "y" character per line, then you can run yes yes as seen in the third example.

like image 29
BMitch Avatar answered Oct 22 '22 00:10

BMitch