If I replace localhost by 127.0.0.1 the healthcheck is working.
So the problem is that it is using ipv6 address ::1 for localhost while it is only listening for ipv4 addresses:
b282259f2feb:/tmp$ netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:40789 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:1880 0.0.0.0:* LISTEN
...
I don't have this for all my node-red containers when comparing the only difference is that localhost is not mapped to ipv6 address "::1" when it is working.
So this is from a container having the problem:
82259f2feb:~$ node --version
v18.18.2
b282259f2feb:~$ uname -a
Linux b282259f2feb 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:10:09 UTC 2024 x86_64 Linux
b282259f2feb:~$
This is from a container not having the problem:
bash-5.1$ node --version
v16.16.0
bash-5.1$ uname -a
Linux bd6ae5207f57 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:10:09 UTC 2024 x86_64 Linux
bash-5.1$
So the problem seems to be caused by more recent node version.
The problem got fixed by upgrading node-red to docker image nodered/node-red:4.0.2-22
as this is using node version v22.6.0 which doesn't have this problem.
Welcome to Node-RED
===================
13 Aug 21:37:01 - [info] Node-RED version: v4.0.2
13 Aug 21:37:01 - [info] Node.js version: v22.6.0
13 Aug 21:37:01 - [info] Linux 6.5.0-44-generic x64 LE