在docker集装箱失败的angular度2应用程序。 无法执行启动脚本。

我有一个angular度服务,快速服务和mongo数据库服务的撰写文件。 当我运行docker-compose up –build时,出现以下错误:

> angular-client@0.0.0 start /usr/src/app/angular > ng serve --host 0.0.0.0.0 --port 4200 2017-06-27T05:25:03.712327811Z sh: 1: ng: not found 2017-06-27T05:25:03.732751350Z npm info lifecycle angular-client@0.0.0~start: Failed to exec start script npm ERR! Linux 4.4.66-boot2docker npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" npm ERR! node v7.10.0 npm ERR! npm v4.2.0 npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! angular-client@0.0.0 start: `ng serve --host 0.0.0.0.0 --port 4200` npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the angular-client@0.0.0 start script 'ng serve --host 0.0.0.0.0 --port 4200'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the angular-client package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! ng serve --host 0.0.0.0.0 --port 4200 npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs angular-client npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls angular-client npm ERR! There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install? 2017-06-27T05:25:03.806272456Z npm ERR! Please include the following file with any support request: npm ERR! /root/.npm/_logs/2017-06-27T05_25_03_786Z-debug.log 

这个docker图像最初是在Ubuntu上创build的,在那里工作正常。 这个问题在我从github / dockerhub下载并从Windows上运行docker-compose时开始发生。

这是我的DOCKERFILE

  # Create image based on official Ubuntu 16.10 image FROM ubuntu:16.10 # Create image based on the official Node 7 image from dockerhub FROM node:7 # Create a directory where our app will be placed RUN mkdir -p /usr/src/app/angular # Change directory so that our commands run inside this new directory WORKDIR /usr/src/app/angular # Copy dependency definitions COPY package.json /usr/src/app/angular # Install dependecies RUN npm install # Get all the code needed to run the app COPY . /usr/src/app/angular # Expose the port the app runs in EXPOSE 4200 # Serve the app CMD ["npm", "start"] 

这是我的package.json

  "name": "angular-client", "version": "0.0.0", "license": "MIT", "angular-cli": {}, "scripts": { "ng": "ng", "start": "ng serve --host 0.0.0.0.0 --port 4200", "test": "ng test", "pree2e": "webdriver-manager update --standalone false --gecko false", "e2e": "protractor" }, "private": true, "dependencies": { "@angular/common": "4.1.3", "@angular/compiler": "*", "@angular/core": "^4.1.3", "@angular/forms": "^4.1.3", "@angular/http": "*", "@angular/platform-browser": "^4.1.3", "@angular/platform-browser-dynamic": "^4.1.3", "@angular/router": "*", "angular2-auth": "*", "angular2-flash-messages": "^1.0.5", "angular2-froala-wysiwyg": "^2.6.0", "angular2-jwt": "^0.2.0", "core-js": "^2.4.1", "ng2-datepicker": "^1.8.3", "ng2-pagination": "^2.0.1", "ngx-dropdown": "0.0.22", "rxjs": "^5.0.1", "ts-helpers": "^1.1.1", "zone.js": "^0.8.4" }, "devDependencies": { "@angular/cli": "^1.0.0", "@angular/compiler-cli": "^4.1.3", "@angular/core": "^4.1.3", "@types/jasmine": "2.5.51", "@types/node": "^7.0.29", "codelyzer": "~3.0.1", "jasmine-core": "2.6.3", "jasmine-spec-reporter": "4.1.0", "karma": "1.7.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.6.0", "protractor": "~5.1.2", "ts-node": "3.0.6", "tslint": "^5.4.3", "typescript": "~2.3.4" } } 

 npm WARN Local package.json exists, but node_modules missing, did you mean to install? 

==>看起来像是在npm buildnpm start之间丢失了node_modules文件夹,但我找不到原因。

尝试只build立到每一步(通过评论所有的指令后),并find什么时候,通过运行一个容器的构build结果( docker run -it --rm <ID_OF_BUILT_IMAGE> bash

BTW:

  • 你的第一个FROM是无用的
  • 最好使用ENTRYPOINT而不是CMD
  • ng servehost参数中有太多0( 0.0.0.0.0不是有效的IP)