java.net.UnknownHostException on Docker

前端 未结 2 1484
耶瑟儿~
耶瑟儿~ 2020-12-05 16:27

I am trying to create docker containers for ZooKeeper and configure them in cluster mode (full code is here and here).

Containers are based on Alpine Linux (alpine:3

相关标签:
2条回答
  • 2020-12-05 16:54

    I managed to get rid of the DNS issues by switching to Oracle JRE 8 and using the following hack in the Dockerfile:

    RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
    

    I created a working Java 8 docker container container on Docker Hub (the code is on github).

    0 讨论(0)
  • 2020-12-05 17:07

    In my case the java application was failing with java.net.UnknownHostException when running in docker. The reason was that I used --network=none docker flag (getting ip/hostname via dhcp and pipework). In this case, docker does not add automatically to /etc/hosts entry like

    127.0.0.1 15e326aecf84

    And getCanonicalHostName() Java function threw this exception.

    Possible solutions:

    • add hostname entry to /etc/hosts file via docker run parameter --hostname=your-hostname.com
    • switch to docker-managed network configuration
    0 讨论(0)
提交回复
热议问题