Dockerfile返回在构建中找不到的npm [英] Dockerfile returns npm not found on build

查看:344
本文介绍了Dockerfile返回在构建中找不到的npm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是Docker的新手,我想创建一个容器,其中包含我所有的Ruby on Rails网站及其依赖项。我阅读了大量的文档和操作方法,但是我一直在努力。

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.

自从我使用Rubymine以来,有一个内置工具可让您对Dockerize您在其中创建的Dockerfile中当前所在的项目。但是,在安装NodeJS 应该的同时,我仍然遇到错误 npm未找到

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.

这是我的Dockerfile:

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"]

最终的目标应该是,因为我在其中使用了Webpacker和React(这是一个测试的虚拟项目,但是真正的网站具有此功能),所以我想安装Yarn,并让Yarn安装所有依赖项。

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.

我发现其他一些人也有同样的问题,但是迷路了要了解Docker层的概念并尝试复制一些也不起作用的代码

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

推荐答案

您需要明确安装node /在运行npm install之前先将npm放入您的容器中。将此添加到您的Dockerfile中。

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

这篇关于Dockerfile返回在构建中找不到的npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆