In containerized Windows environments, there are scenarios where custom font installation becomes essential—particularly for applications that generate documents, perform automated UI rendering, or rely on specific branding requirements. This guide outlines a reliable approach to installing multiple fonts within a Windows-based Docker container.
Use Case
Installing fonts inside a Windows container is particularly useful for:
- Automated document or PDF generation (e.g., via PowerShell, wkhtmltopdf, or .NET libraries)
- Enterprise applications requiring proprietary or brand-specific fonts
- UI testing environments that need consistent font rendering across builds
Prerequisites
- Docker installed on a Windows host system
- A supported base Windows container image (e.g.,
mcr.microsoft.com/windows/servercore:ltsc2022
) - A collection of
.ttf
font files (C:\Windows\Fonts)
Dockerfile Example: Installing Multiple Fonts
To install multiple fonts during the image build process, follow the structure below:
- Place all font files in a local
fonts
directory next to yourDockerfile
. - Use the following sample
Dockerfile
:
FROM mcr.microsoft.com/windows/servercore:ltsc2022
# Create a temporary folder for fonts
RUN mkdir C:\fonts
# Copy all fonts into the container
COPY fonts/ C:/fonts/
# Install fonts and register them in the system
RUN powershell -Command `
$fontPath = 'C:\fonts'; `
$destination = 'C:\Windows\Fonts'; `
$registryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts'; `
Get-ChildItem -Path $fontPath -Filter *.ttf | ForEach-Object { `
Copy-Item $_.FullName -Destination $destination; `
$fontFile = $_.Name; `
$fontName = ($fontFile -replace '.ttf$', '') + ' (TrueType)'; `
New-ItemProperty -Path $registryPath -Name $fontName -PropertyType String -Value $fontFile -Force `
}
Also possible to have it in two lines.
FROM mcr.microsoft.com/dotnet/runtime:8.0-windowsservercore-ltsc2022 AS base
WORKDIR /app
COPY C:/Fonts/ C:/app/Fonts/
RUN powershell -Command "Get-ChildItem -Path 'C:\\app\\Fonts' -Filter '*.ttf' | ForEach-Object { Copy-Item $_.FullName -Destination 'C:\\Windows\\Fonts'; New-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name ($_.BaseName + ' (TrueType)') -PropertyType String -Value $_.Name }"
This script performs the following tasks:
- Copies all
.ttf
files into the system fonts directory (C:\Windows\Fonts
) - Registers each font in the Windows Registry so they are available to all applications running within the container