Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a font to a docker image

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.

like image 354
sripberger Avatar asked Apr 03 '18 19:04

sripberger


1 Answers

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

like image 159
Allen Avatar answered Oct 13 '22 13:10

Allen