Problem
The default locale of the node image is POSIX:
$ docker run --rm node:latest locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
node:19 has the following locales built-in:
$ docker run --rm node:19 locale -a
C
C.UTF-8
POSIX
The POSIX locale doesn't recognize UTF-8 (wc -m counts characters, not bytes).
$ docker run --rm node:latest bash -c 'echo -n 💩 | wc -m'
4
$ docker run --rm node:latest bash -c 'echo -n 💩 | LC_CTYPE=C.UTF-8 wc -m'
1
It is possible to manually enable C.UTF-8:
$ docker run --rm --env LC_CTYPE=C.UTF-8 node:latest bash -c 'echo -n 💩 | wc -m'
1
However in 2023, who doesn't need a locale supporting Unicode? ASCII is a bad default as it doesn't match a 2023 development environment.
Solution
Set LC_CTYPE=C.UTF-8 in the node image. Probably in file /etc/environment.
Problem
The default locale of the node image is
POSIX:node:19has the following locales built-in:The POSIX locale doesn't recognize UTF-8 (
wc -mcounts characters, not bytes).It is possible to manually enable C.UTF-8:
However in 2023, who doesn't need a locale supporting Unicode? ASCII is a bad default as it doesn't match a 2023 development environment.
Solution
Set LC_CTYPE=C.UTF-8 in the node image. Probably in file
/etc/environment.