1

I'm attempting to set up SonarQube in Docker using an Alpine Linux Docker Image. However, when running the image, SonarQube seems to have problem resolving local host. Has anyone experienced this issue before?

Help with this issue would be greatly appreciated!

Dockerfile

FROM gliderlabs/alpine:3.2

ENV SONAR_VERSION=5.6.1 \
    SONARQUBE_HOME=/opt/sonarqube \
    SONARQUBE_FORCE_AUTHENTICATION=true \
    # Database configuration
    # Defaults to using H2
    SONARQUBE_JDBC_USERNAME=sonar \
    SONARQUBE_JDBC_PASSWORD=sonar \
    SONARQUBE_JDBC_URL=

# Http port
EXPOSE 9000

RUN apk -Uu add gnupg curl \
    && rm -rf /var/cache/apk/*

    # pub   2048R/D26468DE 2015-05-25
    #       Key fingerprint = F118 2E81 C792 9289 21DB  CAB4 CFCA 4A29 D264 68DE
    # uid   sonarsource_deployer (Sonarsource Deployer) <infra@sonarsource.com>
    # sub   2048R/06855C1D 2015-05-25
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys F1182E81C792928921DBCAB4CFCA4A29D26468DE

RUN set -x \
    && mkdir /opt \
    && cd /opt \
    && curl -o sonarqube.zip -fSL https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION.zip \
    && curl -o sonarqube.zip.asc -fSL https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION.zip.asc \
    && gpg --batch --verify sonarqube.zip.asc sonarqube.zip \
    && unzip sonarqube.zip \
    && mv sonarqube-$SONAR_VERSION sonarqube \
    && rm sonarqube.zip* \
    && rm -rf $SONARQUBE_HOME/bin/*

VOLUME ["$SONARQUBE_HOME/data", "$SONARQUBE_HOME/extensions"]

WORKDIR $SONARQUBE_HOME
COPY run.sh $SONARQUBE_HOME/bin/
ENTRYPOINT ["./bin/run.sh"]

./bin/run.sh

#!/bin/sh

set -e

if [ "${1:0:1}" != '-' ]; then
  exec "$@"
fi

exec java -jar lib/sonar-application-$SONAR_VERSION.jar \
    -Dsonar.log.console=true \
    -Dsonar.jdbc.username="$SONARQUBE_JDBC_USERNAME" \
    -Dsonar.jdbc.password="$SONARQUBE_JDBC_PASSWORD" \
    -Dsonar.jdbc.url="$SONARQUBE_JDBC_URL" \
    -Dsonar.web.javaAdditionalOpts="$SONARQUBE_WEB_JVM_OPTS -Djava.security.egd=file:/dev/./urandom" \
    "$@"

Docker log

016.08.31 07:56:45 INFO   es[o.s.p.ProcessEntryPoint]  Starting es
2016.08.31 07:56:45 INFO   es[o.s.s.EsSettings]  Elasticsearch listening on 127.0.0.1:9001
2016.08.31 07:56:45 INFO   es[o.elasticsearch.node]  [sonar-1472630204100] version[1.7.5], pid[18], build[00f95f4/2016-02-02T09:55:30Z]
2016.08.31 07:56:45 INFO   es[o.elasticsearch.node]  [sonar-1472630204100] initializing ...
2016.08.31 07:56:45 INFO   es[o.e.plugins]  [sonar-1472630204100] loaded [], sites []
2016.08.31 07:56:45 INFO   es[o.elasticsearch.env]  [sonar-1472630204100] using [1] data paths, mounts [[/opt/sonarqube/data (/dev/vda2)]], net usable_space [55gb], net total_space [59gb], types [ext4]
2016.08.31 07:56:46 WARN   es[o.e.bootstrap]  JNA not found. native methods will be disabled.
2016.08.31 07:56:47 INFO   es[o.elasticsearch.node]  [sonar-1472630204100] initialized
2016.08.31 07:56:47 INFO   es[o.elasticsearch.node]  [sonar-1472630204100] starting ...
2016.08.31 07:56:47 WARN   es[o.e.common.network]  failed to resolve local host, fallback to loopback
java.net.UnknownHostException: 05ae620efc22: 05ae620efc22: unknown error
        at java.net.InetAddress.getLocalHost(InetAddress.java:1505) ~[na:1.8.0_72]
        at org.elasticsearch.common.network.NetworkUtils.<clinit>(NetworkUtils.java:55) ~[elasticsearch-1.7.5.jar:na]
        at org.elasticsearch.transport.netty.NettyTransport.createClientBootstrap(NettyTransport.java:350) [elasticsearch-1.7.5.jar:na]
        at org.elasticsearch.transport.netty.NettyTransport.doStart(NettyTransport.java:242) [elasticsearch-1.7.5.jar:na]
        at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:85) [elasticsearch-1.7.5.jar:na]
        at org.elasticsearch.transport.TransportService.doStart(TransportService.java:153) [elasticsearch-1.7.5.jar:na]
        at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:85) [elasticsearch-1.7.5.jar:na]
        at org.elasticsearch.node.internal.InternalNode.start(InternalNode.java:257) [elasticsearch-1.7.5.jar:na]
        at org.sonar.search.SearchServer.start(SearchServer.java:46) [sonar-search-5.6.1.jar:na]
        at org.sonar.process.ProcessEntryPoint.launch(ProcessEntryPoint.java:102) [sonar-process-5.6.1.jar:na]
        at org.sonar.search.SearchServer.main(SearchServer.java:81) [sonar-search-5.6.1.jar:na]
Caused by: java.net.UnknownHostException: 05ae620efc22: unknown error
        at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_72]
        at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[na:1.8.0_72]
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[na:1.8.0_72]
        at java.net.InetAddress.getLocalHost(InetAddress.java:1500) ~[na:1.8.0_72]
        ... 10 common frames omitted
G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
oyvindym
  • 352
  • 1
  • 2
  • 15
  • I'd try creating a shell into the running container (`docker exec -i -t /bin/bash`) and seeing if you can resolve the hostname from there, e.g. with ping, and have a look at `/etc/resolv.conf` to see how that's set up. But I thought docker took care of all of that for you. – Rup Aug 31 '16 at 08:09

3 Answers3

2

May be there is no Name Service Switch file in Alpine linux, and java need one for java.net.InetAddress.getLocalHost for example.

Add this line in dockerfile

RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' > /etc/nsswitch.conf
gile
  • 5,580
  • 1
  • 25
  • 31
  • Nice +1. Also interesting read: https://github.com/gliderlabs/docker-alpine/issues/11#issuecomment-106233554 – VonC Aug 31 '16 at 09:23
1

Since InetAddress.html#getLocalHost will "retrieving the name of the host from the system", make sure you launch your container with an hostname.

docker run --add-host xxx --hostname yyy 

See docker run Network Settings for --add-host and --hostname options

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • But it has a hostname, albeit an auto-generated one, that should be valid inside the docker world, and should be set up in /etc/hosts even without the --add-host. – Rup Aug 31 '16 at 08:15
  • 1
    @Rup yes, I was thinking more about this old issue https://github.com/weaveworks/weave/issues/68#issuecomment-60494711 – VonC Aug 31 '16 at 08:19
0

I run into a same like issue on k8s and resolved by providing an environment variable to force the DB bind to 127.0.0.1

kubectl run sonarqube --image=sonarqube --port=9092 --env="SONARQUBE_WEB_JVM_OPTS=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dh2.bindAddress=127.0.0.1"
Bruce Zu
  • 507
  • 6
  • 17