Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting custom LANG value for database during creation #3

Open
lospejos opened this issue Sep 16, 2021 · 2 comments
Open

Setting custom LANG value for database during creation #3

lospejos opened this issue Sep 16, 2021 · 2 comments

Comments

@lospejos
Copy link

I would be able to create database using custom encoding, not default en_GB.utf8.

Here


I see constant value en_GB.utf8, but expected to see evaluation of externally set value for LANG and falling back to en_GB.utf8 if it was not set from outside.

Will it work if I set value for LANG in POSTGRES_INITDB_ARGS as described in
https://github.com/yobasystems/alpine-postgres/blob/master/README.md)?

@dominictayloruk
Copy link
Member

Not sure I'll have to have a look, pretty certain the image will need updating as it's old.

@dominictayloruk
Copy link
Member

Just had a look into this, if we wanted to change to Spanish (es_ES);

If we create the following Dockerfile

FROM yobasystems/alpine-postgres:latest

RUN apk --no-cache add \
    tzdata \
    musl-locales \
    musl-locales-lang
RUN cp /usr/share/zoneinfo/Europe/Madrid /etc/localtime
RUN rm -r /usr/share/zoneinfo/Africa && \
    rm -r /usr/share/zoneinfo/Antarctica && \
    rm -r /usr/share/zoneinfo/Arctic && \
    rm -r /usr/share/zoneinfo/Asia && \
    rm -r /usr/share/zoneinfo/Atlantic && \
    rm -r /usr/share/zoneinfo/Australia && \
    rm -r /usr/share/zoneinfo/America  && \
    rm -r /usr/share/zoneinfo/Indian && \
    rm -r /usr/share/zoneinfo/Mexico && \
    rm -r /usr/share/zoneinfo/Pacific && \
    rm -r /usr/share/zoneinfo/Chile && \
    rm -r /usr/share/zoneinfo/Canada
RUN echo "Europe/Madrid" >  /etc/timezone
ENV TZ Europe/Madrid
ENV LANG es_ES.UTF-8
ENV LANGUAGE es_ES.UTF-8
ENV LC_ALL es_ES.UTF-8

ENV MUSL_LOCPATH="/usr/share/i18n/locales/musl"

The we build the container

docker build -t postgres-spanish .

Then we can run the container

docker run --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres-spanish

Then we check the locale in the running container

docker exec -it postgres psql -U postgres -l 

Gives the following results

   Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges
-----------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | es_ES.UTF-8 | es_ES.UTF-8 |            |           |
 template0 | postgres | UTF8     | libc            | es_ES.UTF-8 | es_ES.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |             |             |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | es_ES.UTF-8 | es_ES.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |             |             |            |           | postgres=CTc/postgres

It looks to have change the locale in the db, will need checking further then maybe we can add it into the image without having to rebuild and specify at run time instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants