Install node in Dockerfile? Install node in Dockerfile? jenkins jenkins

Install node in Dockerfile?


I think this works slightly better.

ENV NODE_VERSION=12.6.0RUN apt install -y curlRUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bashENV NVM_DIR=/root/.nvmRUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"RUN node --versionRUN npm --version

Note that nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.


Running apt-get install node does not install Node.js, because that's not the package you're asking for.

If you run apt-cache info node you can see that what you are installing is a "Amateur Packet Radio Node program (transitional package)"

You should follow the Node.js install instructions to install via package manager.

Or if you like building from git, you can just do that inside Docker:

RUN apt-get install -y git-core curl build-essential openssl libssl-dev \ && git clone https://github.com/nodejs/node.git \ && cd node \ && ./configure \ && make \ && sudo make install


Get the node image and put it at the top of your dockerfile:

FROM node:[tag_name] AS [alias_name]

Verify the version by adding following code:

RUN echo "NODE Version:" && node --versionRUN echo "NPM Version:" && npm --version

Then add the following code every time you need to use nodejs in a container:

COPY --from=[alias_name] . .


From the codes above, replace the following with:

[tag_name] - the tag value of the node image you want to use. Visit https://hub.docker.com/_/node?tab=tags for the list of available tags.

[alias_name] - your preferred image name to use in your dockerfile.


Example:

FROM node:latest AS node_baseRUN echo "NODE Version:" && node --versionRUN echo "NPM Version:" && npm --versionFROM php:5.6-apacheCOPY --from=node_base . .### OTHER CODE GOES HERE