[lxc-users] How to set LXD container locale?

zztest at openmailbox.org zztest at openmailbox.org
Sun Mar 20 00:49:20 UTC 2016


On 2016-03-19 10:16, Stéphane Graber wrote:
> On Sat, Mar 19, 2016 at 03:33:11AM -0700, zztest at openmailbox.org wrote:
>> None of the typical ways of setting locales seem to stick in my Ubuntu
>> container in an Ubuntu host (Ubuntu 15.10, LXD 2.0.0.rc4)
>> 
>> The host's locale shows this
>> 
>> LANG=en_US.UTF-8
>> LANGUAGE=
>> LC_CTYPE="en_US.UTF-8"
>> LC_NUMERIC="en_US.UTF-8"
>> LC_TIME="en_US.UTF-8"
>> LC_COLLATE="en_US.UTF-8"
>> LC_MONETARY="en_US.UTF-8"
>> LC_MESSAGES="en_US.UTF-8"
>> LC_PAPER="en_US.UTF-8"
>> LC_NAME="en_US.UTF-8"
>> LC_ADDRESS="en_US.UTF-8"
>> LC_TELEPHONE="en_US.UTF-8"
>> LC_MEASUREMENT="en_US.UTF-8"
>> LC_IDENTIFICATION="en_US.UTF-8"
>> LC_ALL=
>> 
>> 
>> but the container shows this
>> 
>> 
>> LANG=
>> LANGUAGE=
>> LC_CTYPE="POSIX"
>> LC_NUMERIC="POSIX"
>> LC_TIME="POSIX"
>> LC_COLLATE="POSIX"
>> LC_MONETARY="POSIX"
>> LC_MESSAGES="POSIX"
>> LC_PAPER="POSIX"
>> LC_NAME="POSIX"
>> LC_ADDRESS="POSIX"
>> LC_TELEPHONE="POSIX"
>> LC_MEASUREMENT="POSIX"
>> LC_IDENTIFICATION="POSIX"
>> 
>> /etc/default/locale contains the same value (LANG="en_US.UTF-8") in 
>> both the
>> container and the host, but I cannot get it to set in the container. 
>> How is
>> the locale set/changed in an LXD container?
>> 
>> Thanks.
> 
> Note that if you're using "lxc exec", LXD only executes the shell that
> you asked for, it doesn't setup a PAM session for you, so you start 
> with
> an empty environment.
> 
> One way to solve that is to do a "su root" which will then send you
> through the PAM stack (if your container has one) which will then 
> source
> any needed environment.
> 
> Another way if you don't want to go through PAM, is to set environment
> variables directly on the container or one of its profiles, like:
> 
> lxc config set CONTAINER environment.LC_ALL=en_US.UTF-8
> 
> LXD will then set those environment variables for you every time you
> exec a command inside the container.
> 
> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users

Thanks Stéphane. "su <user>" works. What's the difference between that 
and "lxc exec CONTAINER -- /bin/bash"?  And is there another way to 
enter the container without using "lxc exec" that will setup PAM (or at 
least do it automatically)?



More information about the lxc-users mailing list