尝试使用 docker 构建 vue/quasar/node 应用程序时出错:“命令 '/bin/sh -c quasar build' 返回非零代码:1”

Posted

技术标签:

【中文标题】尝试使用 docker 构建 vue/quasar/node 应用程序时出错:“命令 \'/bin/sh -c quasar build\' 返回非零代码:1”【英文标题】:error when trying to build a vue/quasar/node app with docker: "The command '/bin/sh -c quasar build' returned a non-zero code: 1"尝试使用 docker 构建 vue/quasar/node 应用程序时出错:“命令 '/bin/sh -c quasar build' 返回非零代码:1” 【发布时间】:2022-01-01 00:44:36 【问题描述】:

我正在尝试使用 Dockerfile 构建一个 vue/quasar 应用程序并遇到一些错误:

命令“/bin/sh -c quasar build”返回一个非零代码:1

我正在使用最新的 LTS 节点版本。 在应用程序目录中运行命令:npx quaser build 可以正确完成所有工作,但不适用于 Dockerfile。

这是我的 Dockerfile:

FROM node:latest as build-stage
COPY package*.json ./
RUN npm install
RUN npm -g install @quasar/cli
RUN npm -g install @vue/cli

COPY ./ .
RUN quasar build

FROM nginx as production-stage
RUN mkdir /app
COPY --from=build-stage /dist/spa /app
COPY nginx.conf /etc/nginx/nginx.conf

这是所有的输出:

(base) ysgtr@tex-len:~/tex/test$ docker build -t quaser .
Sending build context to Docker daemon  4.085MB
Step 1/11 : FROM node:latest as build-stage
latest: Pulling from library/node
647acf3d48c2: Pull complete 
b02967ef0034: Pull complete 
e1ad2231829e: Pull complete 
5576ce26bf1d: Pull complete 
a66b7f31b095: Pull complete 
2f540184b4cf: Pull complete 
42cd32d0102f: Pull complete 
b8b4c8e22bcd: Pull complete 
48e4c368fbe9: Pull complete 
Digest: sha256:22f1866405ad50bb1d141739596ba803aed073d618ab2ae6d5e66aedcf9261b5
Status: Downloaded newer image for node:latest
 ---> 6dc0a5fbad51
Step 2/11 : COPY package*.json ./
 ---> f80875173de5
Step 3/11 : RUN npm install
 ---> Running in 1282a9fbc81b
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)

added 1183 packages, and audited 1184 packages in 23s

133 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice 
npm notice New patch version of npm available! 8.1.2 -> 8.1.4
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.1.4>
npm notice Run `npm install -g npm@8.1.4` to update!
npm notice 
Removing intermediate container 1282a9fbc81b
 ---> e13c67d85f7b
Step 4/11 : RUN npm -g install @quasar/cli
 ---> Running in 9d0f4ba8e061
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)

added 373 packages, and audited 374 packages in 13s

35 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
Removing intermediate container 9d0f4ba8e061
 ---> 2669c81c7f92
Step 5/11 : RUN npm -g install @vue/cli
 ---> Running in 8340d87251db
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated graphql-extensions@0.15.0: The `graphql-extensions` API has been removed from Apollo Server 3. Use the plugin API instead: https://www.apollographql.com/docs/apollo-server/integrations/plugins/
npm WARN deprecated apollo-tracing@0.15.0: The `apollo-tracing` package is no longer part of Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#tracing for details
npm WARN deprecated apollo-cache-control@0.14.0: The functionality provided by the `apollo-cache-control` package is built in to `apollo-server-core` starting with Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#cachecontrol for details.
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated graphql-tools@4.0.8: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead

added 947 packages, and audited 948 packages in 37s

65 packages are looking for funding
  run `npm fund` for details

15 vulnerabilities (8 moderate, 7 high)

To address issues that do not require attention, run:
  npm audit fix

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
Removing intermediate container 8340d87251db
 ---> 3ecd65ef8620
Step 6/11 : COPY ./ .
 ---> 22470e123db7
Step 7/11 : RUN quasar build
 ---> Running in 0ab8824d1c93

  ___                             
 / _ \ _   _  __ _ ___  __ _ _ __ 
| | | | | | |/ _` / __|/ _` | '__|
| |_| | |_| | (_| \__ \ (_| | |   
 \__\_\\__,_|\__,_|___/\__,_|_|   
 

  Running @quasar/cli v1.2.2

  Example usage
    $ quasar <command> <options>

  Help for a command
    $ quasar <command> --help
    $ quasar <command> -h

  Options
    --version, -v Print Quasar CLI version

  Commands
    create    Create a project folder
    info      Display info about your machine
                   (and your App if in a project folder)
    upgrade   Check (and optionally) upgrade Quasar packages
                   from a Quasar project folder
    serve     Create an ad-hoc server on App's distributables
    help, -h  Displays this message

  --------------
  => IMPORTANT !
  => Trigger this inside of a Quasar project (and npm/yarn install) for more commands.
  --------------


 Error Unknown command "build"

The command '/bin/sh -c quasar build' returned a non-zero code: 1

我尝试过的事情:

更改命令的顺序(quasar/cli 在 vue 之前和相反)。 在运行 docker 文件之前删除 dist/node_modules/ 文件夹。 将 dockerfile 中的 quaser build 替换为 RUN npx quasar build

【问题讨论】:

【参考方案1】:

所以我找到了解决问题的方法,基本上,我声明了 WORKDIR 并复制了 quasar.conf.js 文件。希望这对其他人有所帮助。

FROM node:latest as build-stage
WORKDIR /app

COPY package*.json ./
COPY quasar.conf.js ./
COPY ./ ./

RUN npm install
RUN npm install -g @vue/cli
RUN npm install -g @quasar/cli 
RUN quasar build

FROM nginx as production-stage
RUN mkdir /app
COPY --from=buildenv /app/dist/spa /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

【讨论】:

以上是关于尝试使用 docker 构建 vue/quasar/node 应用程序时出错:“命令 '/bin/sh -c quasar build' 返回非零代码:1”的主要内容,如果未能解决你的问题,请参考以下文章

在 vue3 / quasar2 中访问 $route

尝试使用 gcs json api、axios、vue3、quasar 和 node14 执行单个块可恢复上传到谷歌云存储时出现 cors 错误

Vue/Quasar 和 Capacitor 应用程序的 Auth0 回调 URL

在 Firebase + Vue + Quasar Framework 中更改个人资料图片

如何将来自 Mongoose 的 JSON 映射到 Vue 和 Quasar?

带页脚的 Vue Quasar 布局抽屉