Here is my DockerFile. I also have .dockerignore with (node_modules; .gitignore).
#stage 1
FROM node:alpine as node
WORKDIR /app
COPY . .
RUN npm install
#RUN npm install -g @angular/cli@8.3.29
RUN npm run build --prod
#stage 2
FROM nginx:alpine
COPY --from=node /app/dist/frontend /usr/share/nginx/html
Package.json
{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.2.14",
"@angular/cdk": "~8.2.3",
"@angular/common": "~8.2.14",
"@angular/compiler": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/material": "^8.2.3",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"@material/dialog": "^6.0.0",
"@material/snackbar": "^6.0.0",
"angular-font-awesome": "^3.1.2",
"angular2-multiselect-dropdown": "^4.6.10",
"bootstrap": "^4.6.0",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"highcharts": "^9.3.0",
"highcharts-angular": "^2.10.0",
"jquery": "^3.6.0",
"ng-multiselect-dropdown": "^0.2.14",
"ng2-opd-popup": "^1.1.21",
"ng2-search-filter": "^0.5.1",
"popper.js": "^1.16.1",
"rxjs": "~6.4.0",
"tslib": "^1.14.1",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.29",
"@angular/cli": "^8.3.29",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "^2.0.10",
"@types/node": "~8.9.4",
"codelyzer": "^5.2.2",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.7.0",
"protractor": "^5.4.4",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
}
}
I tried almost everything and went through many threads here but had NO luck :( The CODE works fine on my Machine without any WARN or Error. But After I run docker build to dockerize it:
docker build -t name/app_frontend:latest .
It gives an Error. Here is the complete execution with error:
[+] Building 200.0s (14/15)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 358B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/nginx:alpine 3.4s
=> [internal] load metadata for docker.io/library/node:alpine 3.4s
=> [auth] library/nginx:pull token for registry-1.docker.io 0.0s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 21.13kB 0.0s
=> [node 1/6] FROM docker.io/library/node:alpine@sha256:667dc6ed8fc6623ccd21cb5fa355c90f848daaf5d6df96bc940869bfdf91c19a 0.0s
=> CACHED [stage-1 1/2] FROM docker.io/library/nginx:alpine@sha256:6f94b7f4208b5d5391246c83a96246ca204f15eaf7e636cefda4e6348c8f6101 0.0s
=> CACHED [node 2/6] WORKDIR /app 0.0s
=> [node 3/6] COPY . . 0.1s
=> [node 4/6] RUN npm install 180.7s
=> [node 5/6] RUN npm install -g @angular/cli@8.3.29 6.7s
=> ERROR [node 6/6] RUN npm run build --prod 9.0s
------
> [node 6/6] RUN npm run build --prod:
#14 0.780 npm WARN config production Use `--omit=dev` instead.
#14 0.794
#14 0.794 > frontend@0.0.0 build
#14 0.794 > ng build
#14 0.794
#14 8.969 node:internal/crypto/hash:71
#14 8.969 this[kHandle] = new _Hash(algorithm, xofLen);
#14 8.969 ^
#14 8.969
#14 8.969 Error: error:0308010C:digital envelope routines::unsupported
#14 8.969 at new Hash (node:internal/crypto/hash:71:19)
#14 8.969 at Object.createHash (node:crypto:140:10)
#14 8.969 at module.exports (/app/node_modules/webpack/lib/util/createHash.js:135:53)
#14 8.969 at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:412:16)
#14 8.969 at /app/node_modules/webpack/lib/NormalModule.js:444:10
#14 8.969 at /app/node_modules/webpack/lib/NormalModule.js:320:13
#14 8.969 at /app/node_modules/loader-runner/lib/LoaderRunner.js:367:11
#14 8.969 at /app/node_modules/loader-runner/lib/LoaderRunner.js:203:19
#14 8.969 at VirtualFileSystemDecorator.readFile (/app/node_modules/@ngtools/webpack/src/virtual_file_system_decorator.js:46:13)
#14 8.969 at processResource (/app/node_modules/loader-runner/lib/LoaderRunner.js:202:11)
#14 8.969 at iteratePitchingLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:158:10)
#14 8.969 at runLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:365:2)
#14 8.969 at NormalModule.doBuild (/app/node_modules/webpack/lib/NormalModule.js:292:3)
#14 8.969 at NormalModule.build (/app/node_modules/webpack/lib/NormalModule.js:438:15)
#14 8.969 at Compilation.buildModule (/app/node_modules/webpack/lib/Compilation.js:702:10)
#14 8.969 at /app/node_modules/webpack/lib/Compilation.js:944:14 {
#14 8.969 opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
#14 8.969 library: 'digital envelope routines',
#14 8.969 reason: 'unsupported',
#14 8.969 code: 'ERR_OSSL_EVP_UNSUPPORTED'
#14 8.969 }
#14 8.969
#14 8.969 Node.js v19.7.0
------
executor failed running [/bin/sh -c npm run build --prod]: exit code: 1**