If you want to install all available Google Fonts in a Docker container/image, these Dockerfile commands are for you. Beware though, they add a couple of GB to the image.

Dockerfile

USER root

# Google fonts
RUN wget https://github.com/google/fonts/archive/main.tar.gz -O gf.tar.gz
RUN tar -xf gf.tar.gz
RUN mkdir -p /usr/share/fonts/truetype/google-fonts
RUN find $PWD/fonts-main/ -name "*.ttf" -exec install -m644 {} /usr/share/fonts/truetype/google-fonts/ \; || return 1
RUN rm -f gf.tar.gz
RUN fc-cache -f && rm -rf /var/cache/*

What is it doing?

  1. It downloads all available Google fonts, which are hosted on Github
  2. It untars, “extracts”, the files.
  3. Creates the directory /usr/share/fonts/truetype/google-fonts (the -p flag creates all parent directories if they don’t exist)
  4. Finds all .ttf-files, and runs the install command with them as input
  5. Removes the compressed files downloaded in the first command.
  6. Clears font cache.

That’s it. Enjoy. Check the licenses for each font before use.