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

Stéphane Graber stgraber at ubuntu.com
Sat Mar 19 17:16:10 UTC 2016


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.

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20160319/94a40e42/attachment.sig>


More information about the lxc-users mailing list