我正在尝试使用Alpine Linux Docker Image在Docker中设置SonarQube。但是,在运行映像时,SonarQube似乎在解析本地主机时遇到问题。有没有人以前遇到过这个问题?
非常感谢帮助解决这个问题!
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"]
./仓/ 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日志
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
答案 0 :(得分:2)
可能是Alpine linux中没有名称服务切换文件,例如java需要一个java.net.InetAddress.getLocalHost文件。
在dockerfile中添加此行
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:key name="title-search" match="book" use="a[@n='author']"/>
<xsl:template match="/">
<HTML>
<BODY>
<xsl:for-each select="key('title-search', 'David Perry')">
<DIV>
<xsl:value-of select="a[@n='title']"/>
</DIV>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
答案 1 :(得分:1)
由于InetAddress.html#getLocalHost
将“从系统中检索主机的名称”,因此请确保使用主机名启动容器。
docker run --add-host xxx --hostname yyy
请参阅docker run
Network Settings for --add-host
and --hostname
options
答案 2 :(得分:0)
我在k8s遇到同样的问题并通过提供一个环境变量来强制数据库绑定到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"