【发布时间】:2022-09-30 13:47:23
【问题描述】:
将我的 Angular 项目添加到 docker 后,我刚刚收到此错误。
我将此命令用于 dockerize angular 项目:
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
这是错误:
[+] 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
------
我发现a solution 建议降级节点版本。
正如您在错误消息中看到的那样,它提到了 Node.Js 的 v18.2.0,但我得到了带有 node -v 的 v16.13.1。
-
要获取映像的节点版本,您应该运行
docker run --rm node:latest --version。那是你所做的吗? -
@HansKilian 我用那个命令得到了一些像
67e8aa6c8bbc: Already exists这样的ID。实际上在那个错误中间说Node.js v18.2.0,但这不是我机器上安装的。 -
您正在容器中运行构建,因此根本不使用安装在您机器上的节点版本。