Introduction
During a recent project, there was a requirement to migrate existing ASP.NET apps hosted on Windows to Linux Docker containers. Throughout this migration, numerous challenges arose, and a significant amount of time was dedicated to the migration process. In this post, as well as in subsequent posts with similar titles, I will outline briefly some of the key challenges that were encountered. One of those challenges was Windows Fonts, which this post is dedicated to.
TL;DR
Add the below lines to your Dockerfile on the target runtime container before running your application entry point to install Microsoft Core Fonts:
RUN apt update
RUN apt -y install fontconfig
RUN apt -y install ttf-mscorefonts-installer
RUN fc-cache -f
A Bit of History
Back in 1996, Microsoft started the project “Core Fonts for the Web” to create a standard pack of fonts for the Internet and for their Windows operating systems. This pack includes the fonts Arial, Comic Sans MS, Courier New, Times New Roman and a few others. Over the years, these fonts gained a lot of popularity among Microsoft Windows and Office users. Unfortunately, they are not shipped with Linux.
Microsoft Core Fonts
While porting Windows ASP.NET Core applications to Linux, you might encounter issues in your application if you are using one of Microsoft Windows' core fonts. Fortunately, installing Microsoft Office fonts on Linux is not a challenging task. Follow the steps below to download and install Microsoft Core Fonts on Linux.
Open a terminal window and enter the below command to refresh your package list:
apt update
Now install the fontconfig utility using the below command:
apt install fontconfig
(Optional) You can list the installed fonts by executing the below command:
fc-list
After execution, you should receive output like this:
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book
As you can see from the above list, no Windows fonts are available.
(Optional) You can test the availability of any font by executing the below command:
fc-match Arial
You can see an output like the one below indicates the fonts matching the pattern “Arial”, which is not available in our case:
DejaVuSans.ttf: "DejaVu Sans" "Book"
Now install the “Windows Fonts Installer” package by executing the below command:
apt install ttf-mscorefonts-installer
Next, flush and rebuild the font cache by executing the below command:
fc-cache -f -v
(Optional) Review the font list again by executing:
fc-list
Which will output a very long list of available fonts (output truncated for clarity):
/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf: Times New Roman:style=Italic,ursive,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana
/usr/share/fonts/truetype/msttcorefonts/georgiaz.ttf: Georgia:style=Bold Italic,Negreta ursive,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,Lodi etzana

Join the conversation! Your thoughts help the community grow.