Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install node in Dockerfile?

I am user of AWS elastic beanstalk, and I have a little problem. I want to build my CSS files with less+node. But I don`t know how to install node in my dockerfile, when building with jenkins.

Here is installation packages what I am using in my docker. I will be glad for any suggestions.

FROM php:5.6-apache   # Install PHP5 and modules along with composer binary RUN apt-get update RUN apt-get -y install \     curl \     default-jdk \     git \     libcurl4-openssl-dev \     libpq-dev \     libmcrypt-dev \     libpq5 \     npm \     node \     zlib1g-dev \     libfreetype6-dev \     libjpeg62-turbo-dev \     libpng12-dev  RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/  RUN docker-php-ext-install curl json mbstring opcache pdo_mysql zip gd exif sockets mcrypt  # Install pecl RUN pecl install -o -f memcache-beta \     && rm -rf /tmp/pear \     && echo 'extension=memcache.so' > /usr/local/etc/php/conf.d/memcache.ini 

After this I am runing my entrypoint.sh with code

#!/usr/bin/env sh  composer run-script post-install-cmd --no-interaction  chmod 0777 -R /var/app/app/cache chmod 0777 -R /var/app/app/logs  exec apache2-foreground 

But then I`ve got this error

 Error Output: [2016-04-04 11:23:44] assetic.ERROR: The template ":tmp:module.html.twig" contains an error: A template that extends another one cannot have a body in ":tmp:module.ht     ml.twig" at line 7.      

But when I install inside the Docker container node this way

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

I can build my CSS. So question is..how this installation above make install inside my Dockerfile when I am building it with Jenkins?

like image 784
Delirium Avatar asked Apr 04 '16 10:04

Delirium


People also ask

What is node in Dockerfile?

Worker nodes are also instances of Docker Engine whose sole purpose is to execute containers. Worker nodes don't participate in the Raft distributed state, make scheduling decisions, or serve the swarm mode HTTP API.


2 Answers

I think this works slightly better.

ENV NODE_VERSION=16.13.0 RUN apt install -y curl RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash ENV NVM_DIR=/root/.nvm RUN . "$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 --version RUN 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.

like image 127
Nathan Avatar answered Sep 21 '22 15:09

Nathan


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 
like image 44
Nathaniel Waisbrot Avatar answered Sep 25 '22 15:09

Nathaniel Waisbrot