Skip to content

Getting collations to work on Alpine using ICU #1004

Closed
docker-library/docs
#2220
@lukaromih

Description

@lukaromih

I need custom collations and would really prefer to use Alpine as a base.
I know about Musl (currently) only supporting C or POSIX locales so instead of using a libc as a provider, I tried using icu.

My sources:

I couldn't figure out, why the Docker image postgres:13-alpine doesn't contain all icu locales, because this line in its build source would have me believe it's included already. If anybody could explain that, that would be bonus points.

So I decide to write my own Dockerfile, based on the example of locale customization in Debian based image.

My Dockerfile:

FROM postgres:13-alpine
RUN apk add --no-cache icu-data-full
ENV LANG sl-SI-x-icu

In DB, I test the working of collation:

CREATE TABLE test (some_field text);

INSERT INTO test (some_field)
VALUES ('BA'), ('be'), ('Bi'), ('CA'), ('ce'), ('Ci'), ('ČA'), ('če'), ('Či'), ('DA'), ('de'), ('Di');

SELECT * FROM test ORDER BY some_field;

It returns the values in the wrong order: "BA", "Bi", "CA", "Ci", "DA", "Di", "be", "ce", "de", "ČA", "Či", "če"
I get the same result with:SELECT * FROM test ORDER BY some_field COLLATE "C";

I do get the right result with an explicit: SELECT * FROM test ORDER BY some_field COLLATE "sl-SI-x-icu";
The correct order is: "BA", "be", "Bi", "CA", "ce", "Ci", "ČA", "če", "Či", "DA", "de", "Di"

So Postgres CAN use the collation if instructed so explicitly in every statement (unpractical).
If I do SHOW LC_COLLATE;, it returns sl-SI-x-icu. So it should work, right?
Well, if I change my dockerfile to intead say ENV LANG ghjfgjfc, the container sets up just fine and even SHOW LC_COLLATE; will return "ghjfgjfc" (a nonexistent locale), but keep on using C locale as default.
If I were to set the same gibberish as the LANG environment variable in a Debian based image, it would error out and shut down.

Am I missing something trivial? Should I be setting environment variables differently? Can't it be done with said variables and it could be achieved with a custom initialiaztion script? Should I just give up on Alpine, use Debian and be done with it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions