I was minimizing Oracle-JRE 8 Docker Image to deploy my own playframework app.
Host: CentOS 7 minimal + Oracle JRE 8
The steps are as following:
- Create bash docker image with busybox, since playframework generate bash based startup scripts. I built bash binaries, and use ldd /bin/bash to find related lib so files, and ADD them into the image.
- Create Oracle JRE 8 image from bash-with-busybox with libm-2.17.so libm.so.6 libpthread-2.17.so libpthread.so.0
- Create application container image with some startup scrips from above
- Create playframework container image from above
When I start up the playframework application I came across the following error, which is
Caused by: java.net.UnknownHostException: mysql.server
But when I tried
ping mysql.server
telnet mysql.server 3306
both are working.
And then I searched from internet, and I found some article mentioned that Oracle Java requires nss to resovle server(domain) names, the following command was suggested
echo 'networkaddress.cache.ttl=10' >> $JAVA_HOME/jre/lib/security/java.security
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
I tried, but the hostname still cannot be resolved.
Since I used docker network create a private network, so the /etc/hosts file is as following:
172.18.0.6 4de243ab0668
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.4 redis.server.imadz
172.18.0.5 mysql.server
172.18.0.5 mysql.server.imadz
172.18.0.6 rest.server.imadz
172.18.0.2 activemq.server
172.18.0.2 activemq.server.imadz
172.18.0.4 redis.server
172.18.0.3 mongo.server
172.18.0.3 mongo.server.imadz
172.18.0.6 rest.server
The related exception is as following:
bash-4.3# Java HotSpot(TM) 64-Bit Server VM warning: No monotonic clock was available - timed services may be adversely affected if the time-of-day clock changes
Picked up JAVA_TOOL_OPTIONS: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999
Configuration error: Configuration error[Cannot connect to database [db-server-name]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94)
at play.api.Configuration.reportError(Configuration.scala:743)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238)
at scala.collection.immutable.List.map(List.scala:273)
at play.api.db.BoneCPPlugin.onStart(DB.scala:238)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
at scala.collection.immutable.List.foreach(List.scala:381)
at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:91)
at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.api.Play$.start(Play.scala:90)
at play.core.StaticApplication.<init>(ApplicationProvider.scala:55)
at play.core.server.NettyServer$.createServer(NettyServer.scala:244)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:280)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:275)
at scala.Option.map(Option.scala:146)
at play.core.server.NettyServer$.main(NettyServer.scala:275)
at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2504)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2323)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416)
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:120)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:240)
... 18 more
Caused by: java.net.UnknownHostException: mysql.server
at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:250)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 36 more
I got no clue at all, is it because some required linux libraries are needed or certain binary are required? or it is some other problem, what should be the direction to figure out this issue?
mini-oraclejre8 Dockerfile
FROM bash-on-busybox
RUN mkdir -p /usr/local/lib
ADD server-jre-8u65-linux-x64.tar.gz /usr/local/lib
ADD jre.tar.gz /lib64
ENV JAVA_HOME /usr/local/lib/jdk1.8.0_65
ENV PATH $JAVA_HOME/bin:$PATH
# Fix DNS resolution issues when nss is not installed
RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
# Set DNS cache to 10 seconds (Cache is permanent by default). Network hosts are volatile in Docker clusters.
RUN grep '^networkaddress.cache.ttl=' $JAVA_HOME/jre/lib/security/java.security || echo 'networkaddress.cache.ttl=10' >> /$JAVA_HOME/jre/lib/security/java.security
so files inside lib64
drwxr-xr-x 2 root root 4096 Dec 30 09:39 .
drwxr-xr-x 13 root root 4096 Jan 1 12:36 ..
-rwxr-xr-x 1 root root 164440 Nov 30 20:31 ld-2.17.so
lrwxrwxrwx 1 root root 10 Dec 28 14:37 ld-linux-x86-64.so.2 -> ld-2.17.so
-rwxr-xr-x 1 root root 2107816 Nov 30 20:31 libc-2.17.so
lrwxrwxrwx 1 root root 12 Dec 28 14:37 libc.so.6 -> libc-2.17.so
-rwxr-xr-x 1 root root 19520 Nov 30 20:31 libdl-2.17.so
lrwxrwxrwx 1 root root 13 Dec 28 14:37 libdl.so.2 -> libdl-2.17.so
-rwxr-xr-x 1 root root 1141560 Nov 30 20:31 libm-2.17.so
lrwxrwxrwx 1 root root 12 Dec 28 14:37 libm.so.6 -> libm-2.17.so
-rwxr-xr-x 1 root root 142304 Nov 30 20:31 libpthread-2.17.so
lrwxrwxrwx 1 root root 18 Dec 28 14:37 libpthread.so.0 -> libpthread-2.17.so
lrwxrwxrwx 1 root root 15 Dec 28 13:07 libtinfo.so.5 -> libtinfo.so.5.9
-rwxr-xr-x 1 root root 174520 Jun 10 2014 libtinfo.so.5.9