3

I'm using Packer to build a Docker image based on Ubuntu 14.04, i.e., in my Packer template I have:

"builders": [{
    "type": "docker",
    "image": "ubuntu",
    "commit": true
}],

and I build it using:

$ packer build my.json

What do I need to put in the template to get a specific locale (say en_GB) to be set when I subsequently run the following?

$ sudo docker run %IMAGE_ID% locale

Additional info

As it stands, I get:

LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
...
LC_IDENTIFICATION="POSIX"
LC_ALL=

which causes a few problems for things I want to do next, like installing certain Python packages.

I've tried adding:

{
    "type": "shell",
    "inline": [
        "locale-gen en_GB.UTF-8",
        "update-locale LANG=en_GB.UTF-8 LANGUAGE=en_GB.UTF-8 LC_ALL=en_GB.UTF-8"
    ]
}

but while that does set up the locale config it doesn't affect the env used by docker run. Even if I add extra export lines like:

{
    "type": "shell",
    "inline": [
    ...
        "export LANG=en_GB.UTF-8"
    ]
}

they have no effect, presumably because when using docker run, it's not a child process of the command packer build uses when running these commands initially.

As a workaround I can pass env vars to docker run, but don't want to have to do that each time, e.g.:

sudo docker run -e LANG=en_GB.UTF-8 -e LANGUAGE=en_GB.UTF-8 -e LC_ALL=en_GB.UTF-8 %IMAGE_ID% locale
  • I couldn't tag this 'packer' or 'packer.io' as they're new tags and I've not got the reputation. – Toasty Oct 14 '14 at 17:47
  • I tried a couple things (adding variables to /etc/environment and /root/.profile) but couldn't find a decent workaround. Packer does at least call this out at packer.io/docs/builders/docker.html#toc_8 and they do realize that certain Dockerfile metadata (in this case ENV) isn't available to set. – Andy Shinn Oct 22 '14 at 21:07
  • FYI, packer has been added via a question I asked on Meta Server Fault for the moderators (I don't have sufficient rep to add it directly either). – Misha Brukman Jan 9 '15 at 14:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.