I am trying to create docker containers for ZooKeeper and configure them in cluster mode (full code here and here ).
The containers are based on Alpine Linux (alpine: 3.2 on the Docker Hub), but the problem I'm going to describe also happens with the official Java container (java: 7).
To start the cluster, I use the following commands:
docker run -d -h zk1 --name zk1 dockmob/zookeeper -s zk1,zk2,zk3
(They are available on the docker hub, you can try them).
If I wait a while before starting the second and third containers, the host names zk2 and zk3 will be placed in /etc/hosts too late (via docker) and Java will not be able to find them: I get java.net.UnknownHostException in zk1 for zk2 and zk3 .
I found on the Internet that I needed to disable the JVM DNS cache in order to update host names, so I entered the following command in the Dockerfile command to update the java.security settings:
RUN grep '^networkaddress.cache.ttl=' /usr/lib/jvm/java-1.7-openjdk/jre/lib/security/java.security || echo 'networkaddress.cache.ttl=10' >> /usr/lib/jvm/java-1.7-openjdk/jre/lib/security/java.security
It sets the DNS TTL property ( networkaddress.cache.ttl ) for 10 seconds.
The networkaddress.cache.negative.ttl variable networkaddress.cache.negative.ttl already set to the default value ( 10 ).
The behavior does not change. I get a lot of java.net.UnknownHostException several times.
What could be causing the problem?
source share