【问题标题】:Docker with node.js - Error: .ngxrc not found带有 node.js 的 Docker - 错误:未找到 .ngxrc
【发布时间】:2022-01-22 19:17:49
【问题描述】:

我已经使用以下 docker 文件创建了一个 docker 映像:

FROM node:current-alpine3.14

#install the http-server
RUN npm install -g ngx

# define working directory in docker linux environment
WORKDIR /app

# copy the builded app
COPY /dist/app /app

# start the http-server in the working directory
CMD ngx start

如果我使用以下命令运行 docker 映像:

docker run -p 3000:3000 myapp

我收到以下错误:

Error Error: .ngxrc not found
    at OptionManager._callee2$ (/usr/local/lib/node_modules/ngx/lib/option-manager.js:184:23)
    at tryCatch (/usr/local/lib/node_modules/ngx/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/usr/local/lib/node_modules/ngx/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.<computed> [as throw] (/usr/local/lib/node_modules/ngx/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/usr/local/lib/node_modules/ngx/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /usr/local/lib/node_modules/ngx/node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13

我没有在网上找到有关错误的信息。

有人知道我做错了什么吗?

【问题讨论】:

    标签: node.js docker


    【解决方案1】:

    这是因为您没有将 .ngxrc 配置复制到您的图像中。

    将此文件复制到您的根项目文件夹并修改您的 Dockerfile:

    FROM node:current-alpine3.14
    
    #install the http-server
    RUN npm install -g ngx
    
    
    # define working directory in docker linux environment
    WORKDIR /app
    
    COPY .ngxrc .
    
    # copy the builded app
    COPY /dist/app /app
    
    # start the http-server in the working directory
    CMD ngx start
    

    重建你的镜像并运行容器,错误应该消失了。 当然,您应该修改.ngxrc 以满足您的要求。

    【讨论】:

      猜你喜欢
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 2018-09-23
      • 2021-05-05
      • 1970-01-01
      相关资源
      最近更新 更多