Locales in Ubuntu are slightly complicated. From man locale-gen
:
By default, the locale package which provides the base support for localisation of libc-
based programs does not contain usable localisation files for every supported language.
This limitation has became necessary because of the substantial size of such files and the
large number of languages supported by libc. As a result, Debian uses a special mechanism
where we prepare the actual localisation files on the target host and distribute only the
templates for them.
According to man localedef
, the generated localisation data is kept in
/usr/lib/locale/locale-archive
.
So you could try something like the following:
FROM ubuntu:22.04 AS base
RUN export DEBIAN_FRONTEND=noninteractive; apt-get update; \
apt-get install locales; \
locale-gen da_DK.UTF-8
FROM ubuntu:22.04 AS final
COPY --from=base /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive
In a container based on an image built using this:
root@3a19ac3cde1c:/# (echo aa ;echo b; echo a) | LC_ALL=da_DK.UTF-8 sort | xargs echo ; (echo aa ;echo b; echo a)| sort | xargs echo
a b aa
a aa b
I'm not sure whether this will work for everything, though.