Course contentsShow
← C#
Lesson 1836 of 1,90817. Deployment and Cloud ArchitectureFree lesson

Globalization and Timezone Handling in Alpine Linux

Correctly configure ICU and timezone data for .NET apps running in minimalist Linux distributions.

In this lesson, you will learn how to ensure your .NET applications maintain accurate culture-specific formatting and timezone data when deployed on minimalist Alpine Linux containers.

The Problem: Musl vs. Glibc

Alpine Linux uses musl libc instead of the standard glibc found in distributions like Ubuntu or Debian. Because .NET’s globalization stack historically relied on libicu (which expects a standard environment), running on Alpine often results in "Culture not found" errors or incomplete timezone data. By default, the .NET runtime on Alpine uses an "in-variant" globalization mode unless specifically configured.

Configuring ICU

To enable full globalization support in your Alpine-based container, you must ensure the International Components for Unicode (ICU) libraries are installed and that the runtime is instructed to use them.

First, install the ICU data package in your Dockerfile:

# Install ICU library for full globalization support
RUN apk add --no-cache icu-libs

Next, inform the .NET runtime to stop using the invariant mode by setting the environment variable in your Dockerfile or your Kubernetes deployment manifest:

# Enable full ICU support
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

Handling Timezones

Alpine Linux stores its timezone database in /usr/share/zoneinfo. However, the .NET runtime needs to know where to locate this data. If your container reports UTC regardless of your system settings, you likely need to install the tzdata package:

# Install timezone database
RUN apk add --no-cache tzdata

Once installed, ensure your application isn't accidentally falling back to default UTC behavior by verifying the TZ environment variable is set correctly in your container (e.g., ENV TZ=America/New_York). Without the tzdata package, .NET’s TimeZoneInfo will fail to resolve named timezones, potentially causing your application to drift or return incorrect date offsets for regional users.

By explicitly installing these dependencies and disabling invariant mode, you bridge the gap between the lightweight Alpine base and the robust globalization requirements of enterprise .NET applications.

Key Takeaway: To support full globalization and timezone accuracy on Alpine, you must install icu-libs and tzdata via APK and explicitly set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false.