busybox/nod.js在Kubernetes下运行时出现ELF语法错误



我的node.js kubernetes开发服务器陷入崩溃循环。日志显示:

/bin/busybox:1
ELF
^
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:992:16)
at Module._compile (internal/modules/cjs/loader.js:1040:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:941:32)
at Function.Module._load (internal/modules/cjs/loader.js:776:16)
at Function.executeUserEntryPoint [as runMain (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
stream closed                                                                                                                          

我找到了通过kubectl describe运行的映像,并在shell中运行它。它应该运行这个(从Dockerfile(:

...
ENTRYPOINT ["node", "--max-old-space-size=4096", "--enable-source-maps"]
CMD ['node_modules/.bin/rollup','-cw']

所以我在shell中运行:

❯ dsh myregistry/project/server:R4SUGQt
+dsh:1> docker run --rm -it --entrypoint sh myregistry/project/server:R4SUGQt -c '{ command -v zsh && exec zsh -il ;} || { command -v bash && bash -il ;} || { command -v ash && ash -il ;}'
/bin/ash
06884c20d5cc:/app# node --max-old-space-size=4096 --enable-source-maps node_modules/.bin/rollup -cw

而且效果非常好。那么这个错误是从哪里来的呢?堆栈中的所有路径都跟踪内部(internal/modules/...(,而不是来自我的脚本或汇总。

我使用node:alpine作为我的基本映像,它目前位于Node v14.11.0上。


直接运行

docker run --rm myregistry/project/server:R4SUGQ

不会重现错误。


运行

docker run -it myregistry/project/server:R4SUGQt node_modules/.bin/rollup -cw

工作正常。。。我的CMD语法有问题吗?

CMD ['node_modules/.bin/rollup','-cw']

这是我在CMD中使用的单引号。

事后发现了这篇reddit帖子:https://www.reddit.com/r/docker/comments/9wn5gw/be_aware_of_the_quotes_in_your_dockerfile/

真是浪费时间。。。把这个问题留在这里,以防其他人遇到类似的错误,也许这对他们来说是谷歌的。

我在集群模式下运行pm2时出现此错误。

为了解决这个问题,我刚刚将ecosystem.config.json文件中的script字段从"script": "node src/index.js"(这个字段在不使用集群模式时有效(更改为"script": "src/index.js"

最新更新