Node binary not in PATH
WandersonAlves opened this issue · 5 comments
Hi!
I was playing with this image, and i can't run my project with it. What's the limitations of using this node?
Below is my Dockerfile
FROM astefanutti/scratch-node
ENV NODE_ENV production
WORKDIR /api
COPY ./build ./dist
# Only necessary to debug container in developer machine
# Kubernetes uses ConfigMaps to handle environment variables
COPY .env .env
EXPOSE 3000
# I tried this with ENTRYPOINT [ "./node", "./dist/build.js"] but didn't work either
CMD node dist/build.js
This's the error i got building this Dockerfile:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"./node\": stat ./node: no such file or directory": unknown.
My original Dockerfile is this:
# The only difference between the two files is the FROM line
FROM node:8.9-alpine
ENV NODE_ENV production
WORKDIR /api
COPY ./build ./dist
# Only necessary to debug container in developer machine
# Kubernetes uses ConfigMaps to handle environment variables
COPY .env .env
EXPOSE 3000
CMD node dist/build.js
My package.json dependencies are below:
"dependencies": {
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"@types/mongoose": "^5.0.18",
"@types/redis": "^2.8.6",
"axios": "^0.18.0",
"body-parser": "^1.18.2",
"compression": "^1.7.3",
"concat-stream": "^1.6.2",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"express-validator": "^5.2.0",
"http-status-codes": "^1.3.0",
"husky": "^1.3.1",
"mongodb": "^3.0.4",
"mongoose": "^5.4.14",
"morgan": "^1.9.0",
"prettier": "^1.16.4",
"pretty-quick": "^1.10.0",
"redis": "^2.8.0",
"ts-node": "^7.0.0",
"tslint": "^5.15.0",
"typescript": "^2.9.2",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
},
"devDependencies": {
"@types/body-parser": "^1.17.0",
"@types/express": "^4.16.0",
"@types/node": "^10.3.6",
"source-map-support": "^0.5.9"
}
And these two commands, take care of bundle the service to build/build.js
folder:
"build": "npm run clean && tsc",
"build:webpack": "webpack --config webpack.config.js",
Thanks for testing the image and reporting the issue.
At first glance, it seems you've changed the working directory with WORKDIR /api
and the command calls node
which is not in the path. As a work-around, I would suggest you try by changing your command to:
CMD /node dist/build.js
It would make sense the node
binary gets added to the PATH
.
Hi, thanks for the clarification!
I managed to get this working simple by removing the WORKDIR
line and change CMD
to ENTRYPOINT
, my final Dockerfile is below:
FROM astefanutti/scratch-node
ENV NODE_ENV production
COPY ./build ./dist
# Only necessary to debug container in developer machine
# Kubernetes uses ConfigMaps to handle environment variables
COPY .env .env
EXPOSE 3000
ENTRYPOINT [ "./node", "./dist/build.js"]
Using CMD
i get this error:
internal/modules/cjs/loader.js:613
throw err;
^
Error: Cannot find module '/bin/sh'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
at Function.Module._load (internal/modules/cjs/loader.js:526:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:824:10)
at internal/main/run_main_module.js:17:11
My final image size is this:
REPOSITORY TAG IMAGE ID CREATED SIZE
e3-watson-service dev b587753ddd5d 31 seconds ago 18.2MB
Compared to this (first is alpine, second is a old image with node_modules inside):
e3-order-service dev.2 8aa5f5c156bf 44 hours ago 69.9MB
e3-order-service dev 7024fd311a55 44 hours ago 166MB
Great! Let me keep that issue open as I'll work on adding the node
binary to the PATH
.
Thanks for the detailed report. I'm working on optimizing further the image size so you should expect a 7MB reduction.
Thank you for this awesome image. I'll deploy my services with this on my kubernetes dev cluster asap to test out
It should be fixed with 295a2dc.
I'll re-push the images when I'm done with the multi-architecture support.
Thanks again for your feedback!