-1

I just got this error after adding my angular project to docker.

I used this command to the dockerize angular project:

docker build -t myProject:latest .

Dockerfile:

#stage 1
FROM node:latest as node
WORKDIR / app
COPY. .
    RUN npm install
RUN npm run build

#stage 2
FROM nginx:alpine
COPY --from=node /app/dist/myProject /usr/share/nginx/html

and here is the error:

[+] Building 37.4s(9 / 9) FINISHED
  => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 232B 0.0s
=> [internal] load.dockerignore                                                                                                                                                                             0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:latest 1.8s
=> [internal] load build context                                                                                                                                                                             2.6s
 => => transferring context: 4.04MB 2.5s
=> [1 / 5] FROM docker.io/library/node:latest @sha256:3e2e7e08f088c7c9c0c836622f725540ade205f10160a91dd3cc899170d410ef                                                                                          0.0s
 => CACHED[2 / 5] WORKDIR /app                                                                                                                                                                                 0.0s
 => [3/5] COPY. .                                                                                                                                                                                            7.8s
 => [4/5] RUN npm install                                                                                                                                                                                    15.4s
 => ERROR[5 / 5] RUN npm run build                                                                                                                                                                             9.9s
------
 > [5/5] RUN npm run build:
#9 0.792
#9 0.792 > client@0.0.0 build
#9 0.792 > ng build
#9 0.792
#9 2.803 - Generating browser application bundles (phase: setup)...
#9 9.807 node:internal/crypto/hash:67
#9 9.807   this[kHandle] = new _Hash(algorithm, xofLen);
#9 9.807                   ^
#9 9.807 
#9 9.807 Error: error:0308010C:digital envelope routines::unsupported
#9 9.807     at new Hash (node:internal/crypto/hash:67:19)
#9 9.807     at Object.createHash (node:crypto:133:10)
#9 9.807     at BulkUpdateDecorator.hashFactory (/app/node_modules/webpack/lib/util/createHash.js:145:18)
#9 9.807     at BulkUpdateDecorator.update (/app/node_modules/webpack/lib/util/createHash.js:46:50)
#9 9.807     at RawSource.updateHash (/app/node_modules/webpack/node_modules/webpack-sources/lib/RawSource.js:77:8)
#9 9.807     at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:880:17)
#9 9.807     at handleParseResult (/app/node_modules/webpack/lib/NormalModule.js:946:10)
#9 9.807     at /app/node_modules/webpack/lib/NormalModule.js:1040:4
#9 9.807     at processResult (/app/node_modules/webpack/lib/NormalModule.js:755:11)
#9 9.807     at /app/node_modules/webpack/lib/NormalModule.js:819:5 {
#9 9.807   opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
#9 9.807   library: 'digital envelope routines',
#9 9.807   reason: 'unsupported',
#9 9.807   code: 'ERR_OSSL_EVP_UNSUPPORTED'
#9 9.807 }
#9 9.807
#9 9.807 Node.js v18.2.0
------
executor failed running[/ bin / sh - c npm run build]: exit code: 1
PS D:\dotnet Core\client> set NODE_OPTIONS = --openssl - legacy - provider
PS D:\dotnet Core\client> docker build -t myprojectlient:latest.
[+] Building 15.0s (10/10) FINISHED
=> [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 32B 0.0s
=> [internal] load.dockerignore                                                                                                                                                                             0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:latest 3.1s
=> [auth] library / node:pull token for registry-1.docker.io                                                                                                                                                   0.0s
 => [internal] load build context                                                                                                                                                                             3.2s
 => => transferring context: 4.04MB 3.1s
=> [1 / 5] FROM docker.io/library/node:latest @sha256:3e2e7e08f088c7c9c0c836622f725540ade205f10160a91dd3cc899170d410ef                                                                                          0.0s
 => CACHED[2 / 5] WORKDIR /app                                                                                                                                                                                 0.0s
 => CACHED[3 / 5] COPY . .                                                                                                                                                                                     0.0s
 => CACHED[4 / 5] RUN npm install                                                                                                                                                                              0.0s
------

I found a solution that suggests downgrading the node version.

As you can see in the error message it's mentioned v18.2.0 for Node.Js but I get v16.13.1 with node -v.

  • To get the node version of the image, you should run `docker run --rm node:latest --version`. Is that what you've done? – Hans Kilian May 26 '22 at 14:56
  • @HansKilian I got some ids like this `67e8aa6c8bbc: Already exists` with that command. Actually in the middle of that error said `Node.js v18.2.0` but it is not what has been installed on my machine. –  May 26 '22 at 15:04
  • 1
    You're running the build in a container, so the node version installed on your machine isn't used at all. – Hans Kilian May 26 '22 at 15:05
  • Does this answer your question? [Error message "error:0308010C:digital envelope routines::unsupported"](https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported) – Michael Freidgeim Nov 10 '22 at 01:22

3 Answers3

2

On windows terminal you could use :

$env:NODE_OPTIONS="--max-old-space-size=6096 --openssl-legacy-provider"

--max-old-space-size is for big applications that require lots of RAM

--openssl-legacy-provider is to fix the problem related to this question.

AmiNadimi
  • 5,129
  • 3
  • 39
  • 55
1

The proper way of doing this unless you want to update your Angular framework to the latest version is to build with the NODE_OPTIONS='--openssl-legacy-provider' flag:

RUN NODE_OPTIONS='--openssl-legacy-provider' npm run build

See details here

cha
  • 10,301
  • 1
  • 18
  • 26
0

To downgrade to node version 16, do

#stage 1
FROM node:16 as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build

#stage 2
FROM nginx:alpine
COPY --from=node /app/dist/myProject /usr/share/nginx/html

If using webpack 4 is needed, as the solution you've linked implies, then you need to make sure that's what you're referencing in your package.json and package-lock.json files.

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • Does it overwrite on the previous node image? –  May 26 '22 at 15:13
  • No. You can have multiple versions of an image in your repository. I have 10 different node images on my machine right now, so I should probably delete some. – Hans Kilian May 26 '22 at 15:15
  • I just got many many errors such as "error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors" while there is no error when I run project with `ng-serve`. Having said that "strict": false in my tsconfig.json. –  May 26 '22 at 15:28
  • Here I asked that issue as another question. https://stackoverflow.com/questions/72401585/dockerizing-angular-project-error-ng8001-ng8002-ng8003 –  May 27 '22 at 07:17