我们可以使用 pkg
package将NodeJs应用程序转换为二进制文件。我想构建二进制文件,并与Docker scratch
图像运行相同的文件。index.js
const http = require('http')
http.createServer().listen(3000)
Dockerfile
FROM node:10 as build
COPY index.js .
RUN npm i pkg -g && pkg -t node10-alpine-x64 index.js
FROM scratch
COPY --from=build index /index
ENTRYPOINT ["/index"]
运行
docker build -t index . && docker run --rm -it index
时,出现此错误消息-standard_init_linux.go:211: exec user process caused "no such file or directory"
。我想念什么?
最佳答案
scratch
是一个没有任何文件的空镜像,您的二进制文件可能具有依赖性,并且期望某些Linux环境。尝试使用最少的Linux基本镜像而不是草稿-alpine
,debian
和ubuntu
。
关于node.js - 使用暂存Docker镜像运行NodeJs二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60511368/