How to set the locale in a Debian/Ubuntu Docker container
Codemia Knowledge Hub ·
In the Dockerfile, install the locales package, enable the locale you want in /etc/locale.gen, generate it with locale-gen, and set LANG, LANGUAGE and LC_ALL with ENV. Without this, applications fall back to a default locale such as C, which lacks the localized features below.
What the locale controls
A locale defines regional settings for software:
- Character encoding: text files and strings are encoded and decoded correctly, which matters for non-ASCII characters.
- Date and time formats: output matches the conventions of the region.
- Numeric and currency formats: numbers and currencies are presented the local way.
- Sorting and comparison: strings are sorted and compared by local linguistic rules.
Step 1: install the locales package
Step 2: generate the locale and set the environment
sedon/etc/locale.genuncomments theen_US.UTF-8 UTF-8line. This step is essential on Debian: Debian'slocale-genignores its arguments and only builds the locales enabled in/etc/locale.gen, solocale-gen en_US.UTF-8on its own generates nothing and every laterRUNprintslocale: Cannot set LC_CTYPE to default locale: No such file or directory. On Ubuntulocale-gen en_US.UTF-8also works, but thesedversion works on both.locale-gencompiles the enabled locales.ENV LANG=en_US.UTF-8sets the default locale, both language and encoding.ENV LANGUAGE=en_US:encontrols the language of messages shown to users.ENV LC_ALL=en_US.UTF-8overridesLANGand everyLC_*variable, which keeps behavior consistent.
Setting the ENV lines after generation avoids locale warnings from the generating RUN itself.
Step 3: verify the locale
Running locale in the running container should show en_US.UTF-8 as the active setting, and locale -a should list en_US.utf8. Built this way, both debian:bookworm and ubuntu:24.04 list C, C.utf8, en_US.utf8 and POSIX.
Multiple locales and image size
- To get several locales, uncomment each one in
/etc/locale.gen(or append lines such asde_DE.UTF-8 UTF-8) before runninglocale-gen. - Configure locales in the Dockerfile, not by hand in a running container, so the settings persist across container restarts.
- After configuring locales, remove packages and files you no longer need to keep the image small.
Locale commands
| Command | Description |
locale -a | Lists all available locales on the system. |
locale-gen | Generates the locales enabled in /etc/locale.gen. On Ubuntu, locale-gen <locale> also works. |
dpkg-reconfigure locales | Reconfigures and potentially regenerates all locales. |
update-locale | Updates default system locale. Changes take effect after a system-wide re-login. |
Related reading
- How to set the workdir of a container launched by Kubernetes
- How to set user name in container of kubernetes pod?
- How to setup Node environment variable in Dockerfile for running node.js application?
- How to share a file from initContainer to base container in Kubernetes
- How to share my Docker-Image without using the Docker-Hub?
- How to share WebRTC stream from /dev/videoX device from a Chromium on host and Chromium in a docker container
- How to show the run command of a docker container
- How to specify Memory CPU limit in docker compose version 3
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.