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
3
  • I couldn't tag this 'packer' or 'packer.io' as they're new tags and I've not got the reputation.
    – Toasty
    Oct 14, 2014 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, 2014 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). Jan 9, 2015 at 14:58

1 Answer 1

0

I haven't tried it, but according to the documentation, you should be able to do this using the docker-import post-processor: https://www.packer.io/docs/post-processors/docker-import.html

Example:

{
  "type": "docker-import",
  "repository": "local/ubuntu",
  "tag": "latest",
  "changes": [
    "ENV LC_ALL en_GB.UTF-8"
  ]
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .