【问题标题】:Serve Vue js application on docker在 docker 上服务 Vue js 应用程序
【发布时间】:2019-02-16 23:25:19
【问题描述】:

我想 dockerize 我的 vueJs 应用程序。在我的本地机器上,我可以通过运行命令 npm installnpm run serve 在 localhost 上安装和服务我的应用程序强>。

我想创建一个 docker 镜像,所以我写了一个 dockerfile。我的 dockerfile 看起来像这样

FROM Image_Name

WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD ["npm", "serve"]

但我无法使用 docker run 命令运行我的 docker 映像。知道我做错了什么。

运行运行命令后——

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    completion, config, create, ddp, dedupe, deprecate,
    dist-tag, docs, doctor, edit, explore, get, help,
    help-search, hook, i, init, install, install-test, it, link,
    list, ln, login, logout, ls, outdated, owner, pack, ping,
    prefix, profile, prune, publish, rb, rebuild, repo, restart,
    root, run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h     quick help on <command>
npm -l           display full usage info
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    /root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.2.0 /usr/lib/node_modules/npm    

【问题讨论】:

  • 你在运行之前使用docker build构建了容器吗?
  • 请发布您完整的docker run 命令及其输出,以便我们了解发生了什么。
  • @fxgx 是的,我在使用之前构建了容器。
  • 提供包*.json文件

标签: docker vue.js npm


【解决方案1】:

当你试图执行 npm run serve 你应该把 CMD ["npm", "run", "serve"] 在你的 Dockerfile 中。 您缺少 run 部分。

【讨论】:

  • 谢谢,愚蠢的我,这在过去 1 小时里一直困扰着我。
  • 发生在我们最好的人身上 :) 该错误试图告诉您您误用了npm 命令。祝你的项目好运!
猜你喜欢
  • 1970-01-01
  • 2020-12-26
  • 1970-01-01
  • 2020-01-03
  • 2020-11-13
  • 2020-04-11
  • 2020-06-23
  • 2019-12-09
  • 1970-01-01
相关资源
最近更新 更多