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
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
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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With