News for hackers. Stuff that matters.
Re:`COPY –chmod` reduced the size of my container image by 35% by nodesocket on Saturday March 26, 2022 @12:19AM (#30809204)
A very common mistake I see (though not related to image size perse) when running Node apps is to do CMD ["npm", "run", "start"]. This is first memory wasteful, as npm is running as the parent process and forking node to run the main script. Also, the bigger problem is that the npm process does not send signals down to its child thus SIGINT and SIGTERM are not passed from npm into node which means your server may not be gracefully closing connections.
Re:`COPY –chmod` reduced the size of my container image by 35% by latchkey on Saturday March 26, 2022 @12:43AM (#30809287)
> CMD ["npm", "run", "start"]

Probably not the best searchfoo, but confirmed...

https://github.com/search?q=%22CMD+%5B%22npm%22%2C+%22run%22...

[dead]
Re:`COPY –chmod` reduced the size of my container image by 35% by 0des on Saturday March 26, 2022 @02:25AM (#30809732)
How dare you
Re:`COPY –chmod` reduced the size of my container image by 35% by dedoussis on Saturday March 26, 2022 @02:52AM (#30809830)
To avoid any potential issue with signal propagation a good practice is to always use a lightweight init system such as dumb-init [1]. One could assume that the node process would register signal handlers for all possible signals, but I prefer to not have to make this assumption and use an init system instead.

[1] https://github.com/Yelp/dumb-init

Re:`COPY –chmod` reduced the size of my container image by 35% by unmole on Saturday March 26, 2022 @12:23AM (#30809227)
> This is first memory wasteful, as npm is running as the parent process and forking node to run the main script.

With Linux's CoW semantics, wouldn't the child share pages with the parent?

Re:`COPY –chmod` reduced the size of my container image by 35% by nodesocket on Saturday March 26, 2022 @12:26AM (#30809240)
If I exec into a container that runs npm and run top you’ll see npm (parent) using res memory and the node process (child) itself using memory. I’m pretty sure the npm memory is just wasted.
Re:`COPY –chmod` reduced the size of my container image by 35% by arnaudsm on Saturday March 26, 2022 @12:21AM (#30809211)
What do you recommend instead?
Re:`COPY –chmod` reduced the size of my container image by 35% by nodesocket on Saturday March 26, 2022 @12:23AM (#30809221)
Just invoke your script:

CMD ["/usr/local/bin/node", "server.js"]

Re:`COPY –chmod` reduced the size of my container image by 35% by TameAntelope on Saturday March 26, 2022 @12:23AM (#30809222)
pm2 is good for some things.
Re:`COPY –chmod` reduced the size of my container image by 35% by speedgoose on Saturday March 26, 2022 @01:50AM (#30809567)
You shouldn’t use pm2 in software containers. That makes things more complex and not standard.
Re:`COPY –chmod` reduced the size of my container image by 35% by jwdunne on Saturday March 26, 2022 @03:22AM (#30809966)
Can echo this. A colleague’s node container was maxing out CPU and just removing PM2 and running node directly solved the problem. That was easier than debugging why PM2 was having such a hard time.

To be fair, it was a straight up conversion of an old VM in vagrant and Docker was looked at as a one to one replacement before learning otherwise.

Re:`COPY –chmod` reduced the size of my container image by 35% by TameAntelope on Saturday March 26, 2022 @04:28PM (#30815082)
It gives you a bunch of stuff you don’t get running the script directly, and costs nothing, so why wouldn’t I opt for that?

They even have an explicit, “run in container” mode.

Re:`COPY –chmod` reduced the size of my container image by 35% by nodesocket on Saturday March 26, 2022 @12:30AM (#30809248)
pm2 is great when running on servers, but using pm2 in containers feels wrong and again wasteful. Just invoke your script. If it crashes, fine Kubernetes or Docker handles that. Logs, handled by k8s. Monitoring I use DataDog.
Re:`COPY –chmod` reduced the size of my container image by 35% by chousuke on Saturday March 26, 2022 @05:12AM (#30810382)
What's the point of pm2? Every time I've seen it it's just been part of a messy misconfigured system and whatever it's actually doing could've been accomplished entirely with a tiny systemd unit running node directly.
Re:`COPY –chmod` reduced the size of my container image by 35% by TameAntelope on Saturday March 26, 2022 @04:30PM (#30815092)
From their site, I’m on mobile so the paste is a little rough.

BEHAVIOR CONFIGURATION

SOURCE MAP SUPPORT

CONTAINER INTEGRATION

WATCH & RELOAD

LOG MANAGEMENT

MONITORING

MODULE SYSTEM

MAX MEMORY RELOAD

CLUSTER MODE

HOT RELOAD

DEVELOPMENT WORKFLOW

STARTUP SCRIPTS

DEPLOYMENT WORKFLOW

PAAS COMPATIBLE

KEYMETRICS MONITORING

API

Re:`COPY –chmod` reduced the size of my container image by 35% by AtNightWeCode on Saturday March 26, 2022 @02:57AM (#30809850)
That is funny. I would assume we don’t even have NPM installed on the final Docker images. Some people simply don’t know what they are doing.
Re:`COPY –chmod` reduced the size of my container image by 35% by afiori on Saturday March 26, 2022 @02:58AM (#30809860)
does this applies also to npx or yarn?
Re:`COPY –chmod` reduced the size of my container image by 35% by wereHamster on Saturday March 26, 2022 @07:10AM (#30810847)
Yes.