docker容器中的angular 2 app失败。无法执行启动脚本。

时间:2017-06-27 05:57:01

标签: windows angular docker npm angular-cli

我有一个包含角度服务,快速服务和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上创建的,它可以正常工作。当我从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"
     }
   }

1 个答案:

答案 0 :(得分:0)

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

==>您似乎丢失了node_modulesnpm build之间的npm start文件夹,但我找不到原因。

尝试仅构建每个步骤(通过注释后面的所有说明)并通过在构建结果上运行容器来查找丢失的时间(docker run -it --rm <ID_OF_BUILT_IMAGE> bash

顺便说一句:

  • 您的第一个FROM无用
  • 最好使用ENTRYPOINT代替CMD
  • host ng serve参数0.0.0.0.0中的{0} cmd /K "netsh winsock reset & netsh int ipv4 reset"不是有效IP