nodejs / nodejs/docker-node

Set an UTF-8 locale as default, not POSIX

Open
#1,839 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dockerfile
Stars
8.6k
Forks
2k
Avg merge
10h 19m
Merged PRs (30d)
16

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect how the Node image configures /etc/environment, then run the reported docker run --rm node:latest locale and locale -a commands to confirm the available locales. Set the default LC_CTYPE to C.UTF-8 and verify the wc -m Unicode example reports one character without passing an environment override.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker
Domain
infrastructure
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.