Node.js 安装节点10+;alpine linux上的npm

Node.js 安装节点10+;alpine linux上的npm,node.js,ruby-on-rails,linux,docker,npm,Node.js,Ruby On Rails,Linux,Docker,Npm,我正在使用Alpine构建我的Rails应用程序,我对它的一些依赖项有一些问题 现在,这是我的Dockerfile: FROM ruby:2.5.1-alpine ENV BUNDLER_VERSION=2.0.2 RUN apk add --update --no-cache \ binutils-gold \ build-base \ curl \ file \ g++ \ gcc \

我正在使用Alpine构建我的Rails应用程序,我对它的一些依赖项有一些问题

现在,这是我的Dockerfile:

FROM ruby:2.5.1-alpine
ENV BUNDLER_VERSION=2.0.2

RUN apk add --update --no-cache \
        binutils-gold \
        build-base \
        curl \
        file \
        g++ \
        gcc \
        git \
        less \
        libstdc++ \
        libffi-dev \
        libc-dev \ 
        linux-headers \
        libxml2-dev \
        libxslt-dev \
        libgcrypt-dev \
        make \
        netcat-openbsd \
        nodejs \
        openssl \
        pkgconfig \
        postgresql-dev \
        python \
        tzdata \
        yarn 

RUN gem install bundler -v 2.0.2
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install

COPY . /myapp
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 80

CMD ["rails", "server", "-b", "0.0.0.0", "-p", "80"]

我的
entrypoint.sh
文件如下所示:

#!/bin/sh
bundle install
rake db:migrate
rake db:seed
npm install
set -e

rm -f /myapp/tmp/pids/server.pid

exec "$@"

当涉及到
npm安装时
,我在尝试安装
puppeteer@3.0.0
(由于另一个错误,无法使用3.1.0)

以下是安装3.1.0时出现的错误:

/myapp # npm install puppeteer@3.1.0

> puppeteer@3.1.0 install /myapp/node_modules/puppeteer
> node install.js

/myapp/node_modules/puppeteer/install.js:175
            } catch {
                    ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@3.1.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the puppeteer@3.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-26T01_19_13_984Z-debug.log

由于安装3.1.0没有成功,我被告知尝试3.0.0

因此,在尝试安装3.0.0时,会发生以下情况:

/myapp # npm install puppeteer@3.0.0

> puppeteer@3.0.0 install /myapp/node_modules/puppeteer
> node install.js

(node:111) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): The "original" argument must be of type function
(node:111) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
+ puppeteer@3.0.0
added 4 packages in 1.264s
根据,节点版本是旧的。目前,我正在运行nodejs
8.9.3
,如下所示:

/myapp # node -v
v8.9.3
我试图安装nodejs current,但似乎它卸载了npm

如何在不卸载npm的情况下升级我的nodejs版本?如果我再次尝试安装npm,则会发生以下错误:

/myapp # apk add npm
ERROR: unsatisfiable constraints:
  npm (missing):
    required by: world[npm]
/myapp # apk add --update npm
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  npm (missing):
    required by: world[npm]

在Dockerfile或docker-compose.yml文件中为节点指定所需的版本,与使用ruby时一样,
来自ruby:2.5.1-alpine
,否则相应地。

检查此项以获得合适的版本。

您需要使用更新版本的
ruby
,它具有升级版本的
alpine内核。例如,您可以使用
ruby:2.5.3-alpine3.9

FROM ruby:2.5.3-alpine3.9
ENV BUNDLER_VERSION=2.0.2

RUN apk add --update --no-cache \
        binutils-gold \
        build-base \
        curl \
        file \
        g++ \
        gcc \
        git \
        less \
        libstdc++ \
        libffi-dev \
        libc-dev \ 
        linux-headers \
        libxml2-dev \
        libxslt-dev \
        libgcrypt-dev \
        make \
        netcat-openbsd \
        nodejs \
        npm \
        openssl \
        pkgconfig \
        postgresql-dev \
        python \
        tzdata \
        yarn 

RUN gem install bundler -v 2.0.2
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
和少量命令的输出

/ # npm -v
6.4.1
/ # node -v
v10.14.2
/ # cat /etc/issue
Welcome to Alpine Linux 3.9
Kernel \r on an \m (\l)


如果您更改这些
复制Gemfile/myapp/Gemfile
,该怎么办,
COPY Gemfile.lock/myapp/Gemfile.lock
然后
WORKDIR/myapp
@sachithmuhandram发生同样的事情。在
Dockerfile
中添加
apk add npm
怎么样?我得到
错误:不可满足的约束:
运行时出错@sachithmuhandram,节点如何适应这个应用程序堆栈否则呢?您是否可以使用多阶段构建来基于
节点:lts
图像组装前端,然后
将其复制到最终应用程序中?
/ # npm -v
6.4.1
/ # node -v
v10.14.2
/ # cat /etc/issue
Welcome to Alpine Linux 3.9
Kernel \r on an \m (\l)