【发布时间】:2017-01-19 23:59:44
【问题描述】:
我正在尝试使用 ionic 框架 2 创建一个 docker 环境(我希望与 git 和我的团队一起使用)。
我有一个名为 ionic-boilerplate 的项目目录。在这个目录中,我有一个没有 node_modules 文件夹的离子应用程序。当我执行 docker-compose up --build 命令时,我会在我的 docker 中安装我需要的所有 depdancies。
这是我的 ionic-boilerplate/Dockerfile:
FROM node:6.9.4
RUN npm install -g cordova@4.2.0 ionic@2.2.1
ENV DOCKER_CONTAINER_APP=/web-app
RUN mkdir -p $DOCKER_CONTAINER_APP
ADD . $DOCKER_CONTAINER_APP
RUN cd $DOCKER_CONTAINER_APP
WORKDIR $DOCKER_CONTAINER_APP
RUN npm install
EXPOSE 8100 35729
CMD ionic serve --all
这是我的ionic-boilerplate/docker-compose.yml:
version: '2'
services:
ionic:
build: .
ports:
- "8100:8100"
- "35729:35729"
volumes:
- .:/web-app
- ./node_modules:/web-app/node_modules
当我启动命令docker-compose up --build 或docker-compose run ionic 时,出现此错误:
Attaching to test_ionic_1
ionic_1 | npm info it worked if it ends with ok
ionic_1 | npm info using npm@3.10.10
ionic_1 | npm info using node@v6.9.4
ionic_1 | npm info lifecycle ionic-hello-world@~preionic:serve: ionic-hello-world@
ionic_1 | npm info lifecycle ionic-hello-world@~ionic:serve: ionic-hello-world@
ionic_1 |
ionic_1 | > ionic-hello-world@ ionic:serve /web-app
ionic_1 | > ionic-app-scripts serve "--all" "--v2" "--address" "0.0.0.0" "--port" "8100" "--livereload-port" "35729"
ionic_1 |
ionic_1 | sh: 1: ionic-app-scripts: not found
ionic_1 |
ionic_1 | npm info lifecycle ionic-hello-world@~ionic:serve: Failed to exec ionic:serve script
ionic_1 | npm ERR! Linux 4.4.0-59-generic
ionic_1 | npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "ionic:serve" "--" "--all" "--v2" "--address" "0.0.0.0" "--port" "8100" "--livereload-port" "35729"
ionic_1 | npm ERR! node v6.9.4
ionic_1 | npm ERR! npm v3.10.10
ionic_1 | npm ERR! file sh
ionic_1 | npm ERR! code ELIFECYCLE
ionic_1 | npm ERR! errno ENOENT
ionic_1 | npm ERR! syscall spawn
ionic_1 | npm ERR! ionic-hello-world@ ionic:serve: `ionic-app-scripts serve "--all" "--v2" "--address" "0.0.0.0" "--port" "8100" "--livereload-port" "35729"`
ionic_1 | npm ERR! spawn ENOENT
ionic_1 | npm ERR!
ionic_1 | npm ERR! Failed at the ionic-hello-world@ ionic:serve script 'ionic-app-scripts serve "--all" "--v2" "--address" "0.0.0.0" "--port" "8100" "--livereload-port" "35729"'.
ionic_1 | npm ERR! Make sure you have the latest version of node.js and npm installed.
ionic_1 | npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
ionic_1 | npm ERR! not with npm itself.
ionic_1 | npm ERR! Tell the author that this fails on your system:
ionic_1 | npm ERR! ionic-app-scripts serve "--all" "--v2" "--address" "0.0.0.0" "--port" "8100" "--livereload-port" "35729"
ionic_1 | npm ERR! You can get information on how to open an issue for this project with:
ionic_1 | npm ERR! npm bugs ionic-hello-world
ionic_1 | npm ERR! Or if that isn't available, you can get their info via:
ionic_1 | npm ERR! npm owner ls ionic-hello-world
ionic_1 | npm ERR! There is likely additional logging output above.
ionic_1 |
ionic_1 | npm ERR! Please include the following file with any support request:
ionic_1 | npm ERR! /web-app/npm-debug.log
ionic_1 | There was an error serving your Ionic application: There was an error with the spawned command: serve
test_ionic_1 exited with code 0
错误发生在Dockerfile指令CMD ionic serve。
在没有 docker 的情况下在本地使用相同的方法,即使命令 npm install 然后 ionic serve 运行良好! docker方法我哪里错了?
【问题讨论】:
-
RUN cd ...和WORKDIR是多余的,或者更准确地说,RUN完全没有任何作用,应该被删除。只保留WORKDIR。 -
@DanLowe 谢谢你,我确实忘记删除这个命令了。
标签: javascript node.js docker ionic-framework docker-compose