distroless/java:11 missing libfreetype.so.6
Description of the issue: The docker images build ok with Jib, but I get an exception thrown when the container runs. The application is a spring boot 2.1.x app that runs ok in the IDE against java 11.
Expected behavior: No exception
Steps to reproduce: Jib a spring boot 2.1.x app that uses the autoSizeColumn feature of apache-poi and attempt to run the container on your local docker.
Environment: Linux / Java 11 / Gradle / Spring boot 2.1.x
jib-gradle-plugin Configuration:
jib {
from {
image = 'gcr.io/distroless/java:11'
}
to {
image = "theimage"
}
container {
jvmFlags = ['-Djava.awt.headless=true']
}
}
Log output:
Caused by: java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-11-openjdk-amd64/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method) ~[na:na]
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2430) ~[na:na]
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2487) ~[na:na]
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2684) ~[na:na]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2638) ~[na:na]
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829) ~[na:na]
at java.base/java.lang.System.loadLibrary(System.java:1867) ~[na:na]
at java.desktop/sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:57) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.desktop/sun.font.FontManagerNativeLibrary.<clinit>(FontManagerNativeLibrary.java:32) ~[na:na]
at java.desktop/sun.font.SunFontManager$1.run(SunFontManager.java:270) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.desktop/sun.font.SunFontManager.<clinit>(SunFontManager.java:266) ~[na:na]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:398) ~[na:na]
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) ~[na:na]
at java.desktop/java.awt.Font.getFont2D(Font.java:497) ~[na:na]
at java.desktop/java.awt.Font.canDisplayUpTo(Font.java:2246) ~[na:na]
at java.desktop/java.awt.font.TextLayout.singleFont(TextLayout.java:469) ~[na:na]
at java.desktop/java.awt.font.TextLayout.<init>(TextLayout.java:530) ~[na:na]
at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273) ~[poi-4.0.1.jar:4.0.1]
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:248) ~[poi-4.0.1.jar:4.0.1]
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:233) ~[poi-4.0.1.jar:4.0.1]
at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:2215) ~[poi-4.0.1.jar:4.0.1]
I can create a minimal application with the issue if needed.
yeah we probably need to add it in here: https://github.com/GoogleContainerTools/distroless/blob/master/java/BUILD#L16
but is that a headless dependency? @chanseokoh should we have all of these: https://packages.debian.org/stretch-backports/openjdk-11-jre-headless ?
libfreetype6 is indeed a dependency for both openjdk-8-jre-headless and openjdk-11-jre-headless. I guess it's just that no one so far has hit this problem. I'll add that dependency to the Distroless images.
I don't know if this helps, but in the slim openjdk image it appears both freetype and fontconfig needed to be added to resolve a similar issue: https://github.com/docker-library/openjdk/blob/master/11/jdk/oracle/Dockerfile#L10
Yeah are we gonna run into the fontconfig issue as soon as we add freetype?
Thanks for the info. Good to know.
However, I think I'll just add libfreetype6 (and libpng16-16 required by libfreetype6), because libfontconfig1 pulls in too many transitive dependencies and no one has reported a problem so far. Hopefully libfreetype6 alone resolves this issue.
@loosebazooka no idea, but I'd like to check if that happens.
I can certainly test if libfreetype6 alone does the trick. Let me know how to proceed.
@bentsolheim I've pushed it to francium25/distroless-java11 on Docker Hub. Try that image as a base image and let us know.
It still fails, though in a slightly different manner;
Caused by: java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) ~[na:na]
at java.desktop/java.awt.Font.getFont2D(Font.java:497) ~[na:na]
at java.desktop/java.awt.Font.canDisplayUpTo(Font.java:2246) ~[na:na]
at java.desktop/java.awt.font.TextLayout.singleFont(TextLayout.java:469) ~[na:na]
at java.desktop/java.awt.font.TextLayout.<init>(TextLayout.java:530) ~[na:na]
at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273) ~[poi-4.0.1.jar:4.0.1]
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:248) ~[poi-4.0.1.jar:4.0.1]
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:233) ~[poi-4.0.1.jar:4.0.1]
at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:2215) ~[poi-4.0.1.jar:4.0.1]
[...]
Caused by: java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84) ~[na:na]
... 270 common frames omitted
Caused by: java.lang.NullPointerException: null
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262) ~[na:na]
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225) ~[na:na]
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107) ~[na:na]
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719) ~[na:na]
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:367) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:312) ~[na:na]
at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35) ~[na:na]
at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56) ~[na:na]
... 275 common frames omitted
I guess the root cause points to fontconfig also being required to fix this.
Thanks. I'll add libfontconfig1 too, but this will take some time on my side.
@chanseokoh No worries. I'm impressed and thankful we got this far, this quickly! Thank you for you efforts. I will retest once you get a chance to look into this.
@bentsolheim I've pushed francium25/fontconfig-distroless-java11 (note the new name to avoid accidental caching). I didn't add all transitive deps, but I feel this will work.
Surprisingly it still fails in the exact same way. I dug a bit deeper and enabled debugging by setting the sun.java2d.debugfonts flag and get the following output:
2019-03-14 04:48:56.507 INFO 1 --- [nio-8080-exec-1] sun.java2d : ParseFontDir /usr/lib/jvm/java-11-openjdk-amd64/lib/fonts
2019-03-14 04:48:56.510 INFO 1 --- [nio-8080-exec-1] sun.java2d : Creating standard Font Configuration
2019-03-14 04:48:56.511 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for text fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.Linux.4.9.125-linuxkit.properties
2019-03-14 04:48:56.512 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for binary fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.Linux.4.9.125-linuxkit.bfc
2019-03-14 04:48:56.513 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for text fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.Linux.4.properties
2019-03-14 04:48:56.513 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for binary fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.Linux.4.bfc
2019-03-14 04:48:56.514 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for text fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.Linux.properties
2019-03-14 04:48:56.514 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for binary fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.Linux.bfc
2019-03-14 04:48:56.515 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for text fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.4.9.125-linuxkit.properties
2019-03-14 04:48:56.515 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for binary fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.4.9.125-linuxkit.bfc
2019-03-14 04:48:56.516 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for text fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.4.properties
2019-03-14 04:48:56.516 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for binary fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.4.bfc
2019-03-14 04:48:56.516 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for text fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.properties
2019-03-14 04:48:56.517 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Looking for binary fontconfig file : /usr/lib/jvm/java-11-openjdk-amd64/lib/fontconfig.bfc
2019-03-14 04:48:56.517 INFO 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Did not find a fontconfig file.
2019-03-14 04:48:56.551 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for sans:regular:roman
2019-03-14 04:48:56.552 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for sans:bold:roman
2019-03-14 04:48:56.552 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for sans:regular:italic
2019-03-14 04:48:56.552 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for sans:bold:italic
2019-03-14 04:48:56.552 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for serif:regular:roman
2019-03-14 04:48:56.552 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for serif:bold:roman
2019-03-14 04:48:56.553 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for serif:regular:italic
2019-03-14 04:48:56.553 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for serif:bold:italic
2019-03-14 04:48:56.553 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for monospace:regular:roman
2019-03-14 04:48:56.553 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for monospace:bold:roman
2019-03-14 04:48:56.553 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for monospace:regular:italic
2019-03-14 04:48:56.554 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no font for monospace:bold:italic
2019-03-14 04:48:56.554 INFO 1 --- [nio-8080-exec-1] sun.java2d : Fontconfig returned no fonts at all.
2019-03-14 04:48:56.554 WARN 1 --- [nio-8080-exec-1] sun.awt.FontConfiguration : Failed to get info from libfontconfig
my jib config is now
jib {
from {
image = 'francium25/fontconfig-distroless-java11'
}
to {
image = "---"
}
container {
jvmFlags = ['-Djava.awt.headless=true', '-Dsun.java2d.debugfonts=true']
}
}
Can you provide us with a small sample to reproduce this? That will be faster to resolve this.
Yes, I can certainly do that. I will put something together this evening and get back to you. Hopefully within 6-8 hours.
@chanseokoh I have created a small application that illustrates the issue, and that will blow up on start up. The example also includes instructions on how to make the application run successfully using a standard openjdk image.
https://github.com/bentsolheim/distroless-java11-fontfail
So this required installing libexpat1, fonts-dejavu-core, fontconfig-config, and libfontconfig1, in addition to libfreetype6 and libpng16-16.
@bentsolheim the image francium25/final-distroless-java11 should work now.
This is great stuff! I can verify that everything appears to work correctly now with your final adjustments, @chanseokoh . Thank you very much for your efforts!
Hopefully the required adjustments are not too controversial to be allowed into the main line?
#322 adds these packages. Once it gets merged, they will be available in the main distroless Java images.
Perfect! I'll keep an eye out. Thank you again.