Install Microsoft Fonts Inside Docker

If you need Arial or some other Microsoft “Core Fonts” in your Docker or other headless installation, you might be tempted to just copy the fonts from your Windows installation, check them into your source control, and then copy it from there into the container, but reading the official Microsoft font FAQ and probably also somewhere buried in the EULA or font license, it’s not allowed to redistribute the font.

Comic Sans MS
Courier New
Times New Roman
Trebuchet MS

Web searches will quickly point you to the msttcorefonts or ttf-mscorefonts-installer packages, but only the later is actually available on Debian or Ubuntu. The issue here is, that the package just runs a post install script that requires you to accept the Microsoft EULA and only then downloads the fonts. So, if you’re in a headless environment, like when building a Docker image, you can’t really accept the EULA on the fly.

After a bit of web searching, I did eventually find an AskUbuntu answer that solved the issue for me:

DEBIAN_FRONTEND noninteractive
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
apt-get update && apt-get install -y --no-install-recommends ttf-mscorefonts-installer

Don’t forget to update the font cache afterwards!

fc-cache -fv

All combined in a Dockerfile could look something like this:

ENV DEBIAN_FRONTEND=noninteractive
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get update \
  && apt-get -y install --no-install-recommends \
RUN fc-cache -fv

You can also use fc-list to check which fonts are available. If the fonts were installed correctly, ls /usr/share/fonts/truetype/msttcorefonts should not return an empty directory with just a README file.

Be extra careful if you’re using some sort of caching, as the fonts might not get cached properly and end up missing.

The reason this is probably, most likely not in violation of any terms, is because it’s using the official font archives, so technically Microsoft is redistributing their own fonts.

Leave a Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.