SonarQube in Docker non riesce a risolvere l'host locale

Sto tentando di impostare SonarQube in Docker utilizzando un'image Alpine Linux Docker . Tuttavia, quando si esegue l'image, SonarQube sembra avere problemi di risoluzione dell'host locale. Qualcuno ha sperimentato questo problema prima?

Aiutare a questo problema sarebbe molto apprezzato!

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) <[email protected]> # 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 "[email protected]" 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" \ "[email protected]" 

Docker log

 016.08.31 07:56:45 INFO es[ospProcessEntryPoint] Starting es 2016.08.31 07:56:45 INFO es[ossEsSettings] 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[oeplugins] [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[oebootstrap] 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[oecommon.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 

Può essere che non esista un file di servizio Nome Switch in linux Alpine, e java ha bisogno di uno per java.net.InetAddress.getLocalHost ad esempio.

Aggiungi questa row nel file dockerfile

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

Poiché InetAddress.html#getLocalHost " InetAddress.html#getLocalHost il nome dell'host dal sistema", assicurati di lanciare il contenitore con un hostname.

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

Vedere le impostazioni di networking per il --add-host per le --add-host e --hostname

Ho eseguito uno stesso problema simile a k8s e ho risolto fornendo una variabile di ambiente per forzare il legame DB a 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"