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?
- It downloads all available Google fonts, which are hosted on Github
- It untars, âextractsâ, the files.
- Creates the directory /usr/share/fonts/truetype/google-fonts (the -p flag creates all parent directories if they donât exist)
- Finds all .ttf-files, and runs the install command with them as input
- Removes the compressed files downloaded in the first command.
- Clears font cache.
Thatâs it. Enjoy. Check the licenses for each font before use.