Adding a font to a docker image

19,926

it's the font file had issue, check the report in imageenter image description here

Share:
19,926

Related videos on Youtube

sripberger
Author by

sripberger

Updated on July 13, 2022

Comments

  • sripberger
    sripberger almost 2 years

    My company has a docker image which we use for app engine flex. I need to add a font, and there doesn't seem to be a simple apt package anywhere, so I need to add it manually, following steps like the ones listed here for command-line installation on Linux. Here's what I have so far:

    FROM gcr.io/google_appengine/python
    
    # ...
    
    # Copy the font to the appropriate location.
    # The font is in a ttf in the same directory as the Dockerfile.
    RUN mkdir -p /usr/share/fonts/truetype/noto
    COPY NotoColorEmoji.ttf /usr/share/fonts/truetype/noto
    RUN chmod 644 /usr/share/fonts/truetype/noto/*
    
    # Rebuild the font cache.
    RUN fc-cache -fv
    

    As you can see, the image is based on the GAE base python image. We're adding a few other things, as well, but this is the stuff relevant to the font.

    The fc-cache output when building the image makes it clear that it is detecting one font in the noto directory:

    /usr/share/fonts/truetype/noto: caching, new cache contents: 1 fonts, 0 dirs
    

    And when I log in to a container, I see that the file was indeed copied. I can even run fc-cache again manually and see that same output. The new font, however, is never reflected in fc-list.

    It's been frustrating to diagnose this because following similar steps seems to work perfectly on my own machine. It's almost as if fc-cache is behaving differently in the container.

    Any ideas on what I might be missing?

    Update:

    I added a line to the docker file to explicitly set the correct permissions on the font file after copying it, but it made no difference. This was expected because these commands ultimately run as root, but still it seems like a better practice.

    Interestingly, though, I tried this with a different font (NotoEmoji-Regular.ttf) and it did work. I'll be looking into what the difference between these two fonts might be that is causing this.

    Very frustrating.

    Another Update:

    It seems the primary difference is likely the colors in the font, which is nonstandard in the TrueType format. As comments have pointed out, my system is using a newer version of fontconfig than the docker image, which likely accounts for the discrepancy.

    I'd like to verify this, but it's digging a bit down a rabbit hole that my organization would rather me not spend too much more time on. If anybody is able to do so, however I'd be happy to give you the accepted answer. Otherwise I'm going to have to leave this be for a bit.

    • Tarun Lalwani
      Tarun Lalwani about 6 years
      This may not be a docker issue but the environment of fc version issue. I tested on Ubuntu 16.04 docker and i get fc-list to work fine. The fc-list -V fontconfig version 2.11.94. But for debian 8 and debian 9 the version is 2.11.0. Now it may be possible this is a bug in fc itself or one of the dependencies
    • Venantius
      Venantius about 6 years
      Is hosting your font in cloud storage an option? It sort of sounds to me like you might be setting yourself up for un-needed headache by trying to bundle it with your application.
  • sripberger
    sripberger about 6 years
    Yeah, I imagine these are coming from a compatibility problem due to the use of colors in the font. The more I read about this font, the less I'm surprised by this. It helps to actually see it in the log, though, so thank you!
  • Jean
    Jean about 6 years
    As per this github link github.com/googlei18n/noto-emoji/issues/200 , this seems to be a known issue by the community. Not sure if it will be addressed soon though.