getting java.net.UnknownHostException while running GOCD docker container in QNAP

I am trying to run gocd docker container (https://hub.docker.com/r/gocd/gocd-server/) on QNAP (TS-451 x86 based, firmware 4.2.0) in container station.

container doesn’t’ start and bombs out with java.net.UnknownHostException:

  • Troubles using docker-machine to setup Swarm
  • nginx gunicorn flask packed inside docker compose with redis server. getting exit status on flask part of docker compose
  • systemctl from inside docker container fails with D-Bus connection error
  • repair command in mongodb in docker container
  • How to update docker version in AWS ECS
  • separate applications on kubernetes cluster
  • May 21 20:21:28 gocd-server-1 syslog-ng[16]: syslog-ng starting up; version='3.5.3'                                                                              
    using default settings from /etc/default/go-server                                                                                                               
    ERROR: Failed to start Go server. Please check the logs.                                                                                                         
    java.lang.RuntimeException: gocd-server-1: gocd-server-1                                                                                                         
            at com.thoughtworks.go.util.ExceptionUtils.bomb(ExceptionUtils.java:36)                                                                                  
            at com.thoughtworks.go.server.util.GoSslSocketConnector.getHostname(GoSslSocketConnector.java:102)                                                       
            at com.thoughtworks.go.server.util.GoSslSocketConnector.storeX509Certificate(GoSslSocketConnector.java:92)                                               
            at com.thoughtworks.go.server.util.GoSslSocketConnector.sslConnector(GoSslSocketConnector.java:56)                                                       
            at com.thoughtworks.go.server.util.GoSslSocketConnector.<init>(GoSslSocketConnector.java:51)                                                             
            at com.thoughtworks.go.server.Jetty9Server.sslConnector(Jetty9Server.java:133)                                                                           
            at com.thoughtworks.go.server.Jetty9Server.configure(Jetty9Server.java:76)                                                                               
            at com.thoughtworks.go.server.GoServer.configureServer(GoServer.java:84)                                                                                 
            at com.thoughtworks.go.server.GoServer.startServer(GoServer.java:70)                                                                                     
            at com.thoughtworks.go.server.GoServer.go(GoServer.java:63)                                                                                              
            at com.thoughtworks.go.server.util.GoLauncher.main(GoLauncher.java:31)                                                                                   
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                           
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)                                                                         
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                 
            at java.lang.reflect.Method.invoke(Method.java:606)                                                                                                      
            at com.simontuffs.onejar.Boot.run(Boot.java:306)                                                                                                         
            at com.simontuffs.onejar.Boot.main(Boot.java:159)                                                                                                        
    Caused by: java.net.UnknownHostException: gocd-server-1: gocd-server-1                                                                                           
            at java.net.InetAddress.getLocalHost(InetAddress.java:1496)                                                                                              
            at com.thoughtworks.go.server.util.GoSslSocketConnector.getHostname(GoSslSocketConnector.java:100)                                                       
            ... 15 more                                                                                                                                              
    Caused by: java.net.UnknownHostException: gocd-server-1                                                                                                          
            at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) 
    

    I checked /etc/hosts inside the container – it includes correct host mapping : 10.0.3.2 gocd-server-1

    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
    10.0.3.2 gocd-server-1
    
    hostname resovles correctly:
    root@gocd-server-1:/tmp# hostname
    gocd-server-1
    

    the container image is fine – I have run exactly the same gocd docker container on vagrant Ubuntu vm without any issues

    so the issue is somehow related to QNAP Linux (which seems to be Ubuntu 4.1.2)

    [~] # cat /proc/version
    Linux version 3.12.6 (root@NasX86-12) (gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)) #1 SMP Fri Mar 11 02:20:16 CST 2016)

    any ideas how to get around java.net.UnknownHostException exception?

  • Why are Docker build commands running so slow in Elastic Beanstalk?
  • Migrating Established TCP connection with docker containers
  • Access host machine dns from a docker container
  • How to deploy node app to docker using maven
  • How to properly deploy to host from gitlab-ci (+docker)?
  • Wget in Dockerfile, files disappear in container
  • 2 Solutions collect form web for “getting java.net.UnknownHostException while running GOCD docker container in QNAP”

    To close this thread: though I still don’t understand why this exception happens I think I found the workaround. So if you are the owner of QNAP and want to run GOCD server using ContainerStation the following steps might be useful:
    1. Create a new container, using travix/gocd-server:lastest image (https://hub.docker.com/r/travix/gocd-server/). This container uses JDK8 (instead of JDK7 as official gocd container) plus it includes more options to configure (if you go to advanced settings while creating a container in ContainerStation).
    2. Start the container – you will get the exception – Caused by: java.net.UnknownHostException.

    Why? no idea, I am pretty sure my /etc/hosts settings are correct. In fact I know they are correct.

    1. next step – keep the container running but ssh to your QNAP:

      ssh admin@192.168.1.79 (in my case – change ip of the box to yours)

      // check what images are running:
      docker ps -a

    dde6ce028868 travix/gocd-server:latest “/docker-entrypoint.s” 21 hours ago Up 21 hours 0.0.0.0:32793->8153/tcp, 0.0.0.0:32792->8154/tcp gocd

    // ssh into the container  
    docker exec -it dde6ce028868 bash
    
    // run go-server start script 
    /usr/share/go-server/server.sh 
    

    let it run, in my case it successfully started gocd.

    1. clean up work dir
      rm -rf /var/lib/go-server/work/

    2. and now restart the container from ContainerStation

    in my case it starts up correctly without unknown host exceptions

    any theories why? (DNS caching, permissions, some initialisations which silently fail?)

    it turned out the issue is related to ACL which gives read access to /etc/hosts and /etc/resolv.conf only to root. So java application running inside the container under a different user, can’t access these files.

    pls. see this discussion for more information:.

    why am I getting permission denied on file with read permissions inside Docker container?

    if you want to use GOCD with QNAP – you might try to use this container https://hub.docker.com/r/rshestakov/docker-gocd-server/

    which includes the following fix:

    # modify ACL so go user would have read access
    # to /etc/hosts and /etc/resolv.conf
    # this is to avoid HostUnknown exception which happends
    # when the gocd container is used on QNAP with ContainerStation
    setfacl -m user:${USER_ID}:r /etc/resolv.conf
    setfacl -m user:${USER_ID}:r /etc/hosts
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.