Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile returns npm not found on build

I'm really new to Docker and would like to create a container that has all my Ruby on Rails website and its dependencies in it. I read TONS of documentations and how-to's to do it but I keep struggling.

Since I use Rubymine, there is a built-in tool that allows you to Dockerize the current project you're in from the Dockerfile you created in it. However, I keep having the error "npm not found while NodeJS should be installed.

Here is my Dockerfile:

FROM ruby:2.4.3
MAINTAINER Jaeger
RUN apt-get update -qq && apt-get install -y build-essential nodejs

RUN mkdir -p /app
WORKDIR /app

COPY package.json /app
RUN npm i -g yarn && yarn

COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5
RUN yarn

COPY . ./

EXPOSE 3000

CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

The ultimate goal should be that, since I use Webpacker and React in it (well it's a dummy project for a test, but the real website has this), I would like to install Yarn, and make Yarn install all the depencies.

I found some other people that had the same problem but got lost trying to understand the Docker layers concept and trying to copy some codes that didn't work either

like image 290
Jaeger Avatar asked Mar 03 '18 20:03

Jaeger


2 Answers

You need to explicitly install node / npm in your container before running npm install. Add this to your Dockerfile.

RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get update && apt-get install -y nodejs
like image 113
rgon Avatar answered Oct 16 '22 22:10

rgon


Another solution (which might be cleaner) would be to first mount / setup the working directory before installing the dependencies:

FROM ruby:2.4.3
MAINTAINER Jaeger

RUN mkdir -p /app
WORKDIR /app

RUN apt-get update -qq && apt-get install -y build-essential nodejs

...
like image 1
magicturtle Avatar answered Oct 17 '22 00:10

magicturtle