In this post I will describe how to install fonts in Docker containers, via the Dockerfile.

Let’s say you have a custom font downloaded in ttf format, that you wish to use within your container. The .ttf-file is located in your project root in your host OS. This Dockerfile installs the custom font in an Alpine image.

FROM alpine:3.14
WORKDIR /app
COPY ./my-custom-font.ttf ./
RUN mkdir -p /usr/share/fonts/truetype/
RUN install -m644 my-custom-font.ttf /usr/share/fonts/truetype/
RUN rm ./my-custom-font.ttf

It is as easy as that! Enjoy your new font! Please comment if you have any questions.