title: Adding a font to a docker image
body: <p>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 <a href="https://www.google.com/get/noto/help/install/" rel="noreferrer">here</a> for command-line installation on Linux. Here's what I have so far:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>The <code>fc-cache</code> output when building the image makes it clear that it is detecting one font in the noto directory:</p>
  
  <pre><code>/usr/share/fonts/truetype/noto: caching, new cache contents: 1 fonts, 0 dirs
  </code></pre>
  
  <p>And when I log in to a container, I see that the file was indeed copied. I can even run <code>fc-cache</code> again manually and see that same output. The new font, however, is never reflected in <code>fc-list</code>.</p>
  
  <p>It's been frustrating to diagnose this because following similar steps seems to work perfectly on my own machine. It's almost as if <code>fc-cache</code> is behaving differently in the container.</p>
  
  <p>Any ideas on what I might be missing?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>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.</p>
  
  <p>Interestingly, though, I tried this with a different font (NotoEmoji-Regular.ttf) and it <em>did</em> work. I'll be looking into what the difference between these two fonts might be that is causing this.</p>
  
  <p>Very frustrating.</p>
  
  <p><strong>Another Update:</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>