Bruno Mateiro
Bruno Mateiro

Reputation: 13

Setting locale inside docker container

My container has locale settep up to POSIX and I want to change it. After I do that, I exit and reenter the container and the locale is back to POSIX. I don't want to build a new image or run a new container because we have a lot of containers in several machines.

Running this:

DEBIAN_FRONTEND=noninteractive apt-get install -y locales
sed -i -e 's/# pt_PT ISO-8859-1/pt_PT ISO-8859-1/' /etc/locale.gen
dpkg-reconfigure --frontend=noninteractive locales
export LANGUAGE=pt_PT
export LANG=pt_PT
export LC_ALL=pt_PT

Works great in running container but exiting and reentering the container makes the changes lost.

Already tried this code in container Entrypoint but the export doesn't have any effect.

Upvotes: 1

Views: 8005

Answers (2)

Vinod
Vinod

Reputation: 533

changes can't be stored in the container. I think the best way is to commit your changes into the container and create a new one.

you can use "docker commit" for this purpose.

docker commit

Ref: https://docs.docker.com/engine/reference/commandline/commit/

Upvotes: 0

samthegolden
samthegolden

Reputation: 1490

Those settings are shell-session bound, not OS-bound. To make it OS-bound, you should write it in OS files, but when the service restarts it will apply the image without those changes.

So, that has to be set in Dockerfile, to be image-bound, something like:

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y locales && \
    sed -i -e 's/# pt_PT ISO-8859-1/pt_PT ISO-8859-1/' /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales
ENV LANG pt_PT  
ENV LANGUAGE pt_PT  
ENV LC_ALL pt_PT  

Upvotes: 2

Related Questions