I'm building a docker image based on Ubuntu 14.04
and am having troubles to set the locale correctly.
(I know 14.04 is EOL and all but it should still work as well, right? I was denied support from the Ubuntu people on askubuntu.com, hence I'm trying my luck here)
My Dockerfile
looks like:
COPY .bashrc /root/.bashrc
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get install -y build-essential \
locales
RUN dpkg-reconfigure locales
WORKDIR /home/prs/
Where .bashrc
is:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
it will build with no errors docker build -t "test" .
but when I run it, I get the following output:
$ docker run -it test
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8): No such file or directory
root@d09247a538eb:/# source /root/.bashrc
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
root@d09247a538eb:/#
I also tried:
echo "LANG=en_US.UTF-8" > /etc/locale.conf
I still get:
# locale-gen
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
What's going on with this? And how can the locale be set correctly?
UPDATE:
It seems like that if I base my container image off of Ubuntu 18.04
, I get to choose a locale
when I type # dpkg-reconfigure locales
but with 14.04
(which is what I currently need) I get the following:
# dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
AS suggested below by Eduardo Trápani (@EduardoTrápani), I also tried to run the locale setting manually:
# echo "en_US.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen
en_US.UTF-8 UTF-8
# locale-gen
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Another hint may be, that there is nothing in the locales/sup[ported.d directory (which should be the result of locale-gen
if I understand this correctly from http://manpages.ubuntu.com/manpages/precise/man8/locale-gen.8.html):
# ls -l /var/lib/locales/supported.d/
total 0
/etc/locale.gen
and runninglocale-gen
like in stackoverflow.com/a/28406007/10931455./etc/locale.gen
, I had to create it first.