angulardockernomachine-nx

Docker build error while running nx build


I have an angular ssr application that I build into an image. I faced a really strange situation. My docker build always failing when i run the nx build command,exit code 1. The most fustrating thing that on docker desktop->builds-> error shows red text with some warnings and this line:

NX Successfully ran target build for project bringaznimentem-fe

I tried that to comment out the build command and set the entrypoint to get a runnable image. After i run a container with this image can sucessfully execute the nx build command inside the container, so really dont have any idea what's the problem with that. Docker file:

FROM node:16-alpine3.17 as build-stage
WORKDIR /app
COPY package*.json /app/

RUN npm install
# RUN npm i -g @angular/cli
RUN npm install -g @nrwl/cli
RUN npm install --global nx@latest

COPY ./ /app/
ARG configuration=production
RUN nx build # this line is failing
RUN nx run my-project:server

FROM node:16-alpine3.17 AS ssr-server
WORKDIR /app
COPY --from=build-stage /app/dist/ /app/dist/
COPY ./package.json /app/package.json

EXPOSE 4000
CMD ["node", "./dist/my-project/server/main.js"]

Node: 18.12.1 Package Manager: npm 9.6.6 OS: win32 x64

Angular: 15.1.5 ... animations, common, compiler, compiler-cli, core, forms ... platform-browser, platform-browser-dynamic, platform-server ... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1501.6
@angular-devkit/build-angular   15.1.6
@angular-devkit/core            15.1.6
@angular-devkit/schematics      15.2.10
@angular/cdk                    15.2.5
@angular/cli                    15.2.10
@angular/google-maps            14.2.7
@nguniversal/builders           15.1.0
@nguniversal/express-engine     15.1.0
@schematics/angular             15.2.10
rxjs                            6.6.7
typescript                      4.9.5

  "dependencies": {
    "@angular/animations": "^15.1.5",
    "@angular/cdk": "^15.2.5",
    "@angular/common": "^15.1.5",
    "@angular/compiler": "^15.1.5",
    "@angular/core": "^15.1.5",
    "@angular/forms": "^15.1.5",
    "@angular/google-maps": "^14.2.7",
    "@angular/platform-browser": "^15.1.5",
    "@angular/platform-browser-dynamic": "^15.1.5",
    "@angular/platform-server": "^15.1.5",
    "@angular/router": "^15.1.5",
    "@fortawesome/angular-fontawesome": "^0.12.1",
    "@fortawesome/fontawesome-svg-core": "^6.4.0",
    "@fortawesome/free-brands-svg-icons": "^6.4.0",
    "@fortawesome/free-solid-svg-icons": "^6.4.0",
    "@nguniversal/express-engine": "^15.1.0",
    "@types/googlemaps": "^3.39.13",
    "bootstrap": "^5.1.3",
    "express": "^4.15.2",
    "font-awesome": "^4.7.0",
    "helmet": "^7.1.0",
    "https": "^1.0.0",
    "ngx-pagination": "^5.1.1",
    "ngx-sharebuttons": "^12.0.0",
    "rxjs": "~6.6.0",
    "snazzy-info-window": "^1.1.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.1.6",
    "@angular-devkit/core": "^15.1.6",
    "@angular-devkit/schematics": "^15.1.6",
    "@angular/cli": "^15.1.6",
    "@angular/compiler-cli": "^15.1.5",
    "@nguniversal/builders": "^15.1.0",
    "@nrwl/angular": "15.9.2",
    "@nrwl/workspace": "15.9.2",
    "@schematics/angular": "^15.1.6",
    "@types/express": "^4.17.0",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.8.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "^6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "nx": "15.9.2",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.9.5"
  }

Solution

  • Solution is set version for nx in the docker file.

    RUN npm install -g @nrwl/cli@15.9.7
    RUN npm i nx@17.0.0
    

    It would have been great if it had shown a proper error message....