Angular docker-组成不起作用

时间:2018-03-07 08:55:55

标签: angular docker docker-compose dockerfile

我有一个dockerized角度应用程序,使用“docker-compose up”时无法启动。我将应用程序停靠,因为我想将它分发给同学等。

图像的构建工作得很好。

请在帖子末尾找到错误消息。

这是我对角度部分的Dockerfile:

FROM node:9.4.0

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY package.json /usr/src/app

RUN npm install --save

COPY . /usr/src/app

EXPOSE 4200

CMD ["npm", "start"]

这是我的Docker-compose文件的角度相关部分:

angular:
    build: ../angular
    container_name: ng
    ports:
      - "4200:4200"
    volumes:
      - ../angular:/usr/src/app

我在启动时遇到这种错误。

angular@0.0.0 start /usr/src/app

ng serve -H 0.0.0.0

sh: 1: ng: not found

npm ERR! file sh

npm ERR! code ELIFECYCLE

npm ERR! errno ENOENT

npm ERR! syscall spawn

npm ERR! angular@0.0.0 start: `ng serve -H 0.0.0.0`

npm ERR! spawn ENOENT

npm ERR!

npm ERR! Failed at the angular@0.0.0 start script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

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

的package.json

{
  "name": "angular",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve -H 0.0.0.0",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.1.0",
    "@angular/common": "^5.1.0",
    "@angular/compiler": "^5.1.0",
    "@angular/core": "^5.1.0",
    "@angular/forms": "^5.1.0",
    "@angular/http": "^5.1.0",
    "@angular/platform-browser": "^5.1.0",
    "@angular/platform-browser-dynamic": "^5.1.0",
    "@angular/router": "^5.1.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "1.6.4",
    "@angular/compiler-cli": "^5.1.0",
    "@angular/language-service": "^5.1.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}

如果您对dockerfiles或compose文件中的更改有任何想法,请告诉我。 非常感谢你提前。

2 个答案:

答案 0 :(得分:0)

试试这个......

    if (MyApplication.isAppOpen() &&
                DashboardActivity::class.simpleName?
.equals(MyApplication.displayActivity) ?: false) {
// you can eliminate the last condition if you wish

            playAlertTone(context) // or whatever
        } else {
           // your notification building code
        }

答案 1 :(得分:0)

我最终不得不删除容器的卷

docker-compose rm -v angular

这是因为我已经挂载了 node_modules/ 以避免覆盖这些,因为我们通过容器挂载 js 源<->主机挂载以进行热重载。