Score:0

What files need to be copied into Ubuntu docker image to support da_DK.UFT-8 locale?

ag flag

We have a docker image which runs Newman queries against a backend to verify things are as expected. Now we have a new need to test that a response containing Danish characters is sorted correctly in Danish.

The simplest way to do this is to set the locale to Danish using da_DK.UTF-8 as everything just works but those images we have been using so far, do not have this locale installed.

This question explains how to set up the locale but it does that by installing new programs - https://stackoverflow.com/questions/66859800/bin-bash-warning-setlocale-lc-all-cannot-change-locale-en-us-utf-8 - and I was thinking that it might be enough just to copy the data files needed from a populated system instead.

Sample one liner to verify things work as we need them to:

root@2e4c326b456e:/etc/newman# (echo aa ;echo b; echo a)| LC_ALL=da_DK.UTF-8 sort| xargs echo
a b aa

What files should be copied in for this to work?

Gunnar Hjalmarsson avatar
uz flag
What makes you think that figuring out what to copy is easier than running `sudo locale-gen da_DK.UTF-8` ?
Artur Meinild avatar
vn flag
Exploring the [Ubuntu manpage](https://manpages.ubuntu.com/manpages/trusty/man8/locale-gen.8.html) (older version though), and my own system, it seems installed locales are placed in either `/usr/lib/locale/locale-archive` (single file) or in `/usr/lib/locale/<locale_name>/LC_*` (individual folders and files). However, since the format may vary, it's probably easier to follow Gunnar's advice.
ag flag
@GunnarHjalmarsson `sudo localegen` requires `apt install locales` which in turn requires `apt update` which in turn requires Internet access. Copying in one or more static file is easier.
Gunnar Hjalmarsson avatar
uz flag
Well, the `ubuntu-minimal` package depends on `locales`.
Score:1
us flag

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.

ag flag
I did a quick experiment that showed that this file was the only one changed under `/usr` when adding a locale, so that is in agreement t with your findings.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.