node.jsdockerkubernetesbusybox

busybox/node.js giving ELF syntax error when ran under Kubernetes


My node.js kubernetes dev server is stuck in a crash loop. The logs show:

/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                                                                                                                          

I found the image that's running via kubectl describe and ran it in a shell. It ought to be running this (from the Dockerfile):

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

So in the shell I ran:

❯ 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

And it works perfectly. So where's that error stemming from? All the paths in the stack trace internal (internal/modules/...) not from my script or rollup.

I'm using node:alpine as my base image which is currently on Node v14.11.0.


Running it directly

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

does reproduce the error.


Running

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

Works fine... is there something wrong with my CMD syntax?

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

Solution

  • It was the single quotes I used in the CMD.

    Found this reddit post after the fact: https://www.reddit.com/r/docker/comments/9wn5gw/be_aware_of_the_quotes_in_your_dockerfile/

    What a waste of time... leaving this question here in case someone else hits a similar error, maybe it'll be Googlable for them.