2

I'm currently working on a project that uses the python:latest docker image to run tests, as my project requires the use of the locales en_US.UTF-8 and nl_NL.UTF-8 I had to add them in my CI script.

However whenever I try to add them, they don't show up in my locale output (nor is my code able to use them). Does anyone know what I'm doing wrong here?

root@90a95fe4f532:/# locale -a
C
C.UTF-8
POSIX
root@90a95fe4f532:/# locale-gen en_US.UTF-8
Generating locales (this might take a while)...
Generation complete.
root@90a95fe4f532:/# locale-gen nl_NL.UTF-8
Generating locales (this might take a while)...
Generation complete.
root@90a95fe4f532:/# update-locale
root@90a95fe4f532:/# locale -a
C
C.UTF-8
POSIX
root@90a95fe4f532:/# locale-gen nl_NL.UTF-8
Generating locales (this might take a while)...
Generation complete.
root@90a95fe4f532:/# locale -a
C
C.UTF-8
POSIX

I set up my image as follows:

$ docker pull python:latest
$ docker create python:latest --name python
$ docker run -it python /bin/bash

1 Answer 1

3

The best way to properly set locale is through Dockerfile ENV settings.

Create a Dockerfile with the content:

FROM python:latest
RUN apt-get clean && apt-get update && apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    locale-gen
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8

Then create a new image from python docker image. We’ll tag this v1

# docker build -t python:v1 .

Test by running:

# docker run -it --rm --name test python:v1 /bin/bash

If you check your locale, it should reflect correct settings.

root@ee85b63d6ddf:/# locale -a
C
C.UTF-8
en_US.utf8
POSIX

Read more on Aquasec Docker containers Administration guides that covers basic administration to advanced topics.

1
  • Just editing the locale.gen file was enough for me, we don't need to set the locale instantly, just add them to the list of available ones, thanks :)
    – Paradoxis
    Commented Apr 3, 2018 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .