Docker 中的 SonarQube 无法解析本地主机
SonarQube in Docker failes to resolve local host
我正在尝试使用 Alpine Linux Docker Image 在 Docker 中设置 SonarQube。但是,当 运行 图像时,SonarQube 似乎无法解析本地主机。以前有人遇到过这个问题吗?
非常感谢能帮助解决这个问题!
Docker文件
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 日志
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.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
由于 InetAddress.html#getLocalHost
将 "retrieving the name of the host from the system",请确保使用主机名启动容器。
docker run --add-host xxx --hostname yyy
见docker run
Network Settings for --add-host
and --hostname
options
Alpine linux 中可能没有名称服务转换文件,例如 java java.net.InetAddress.getLocalHost 需要一个。
在 dockerfile 中添加这一行
RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' > /etc/nsswitch.conf
我 运行 在 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"
我正在尝试使用 Alpine Linux Docker Image 在 Docker 中设置 SonarQube。但是,当 运行 图像时,SonarQube 似乎无法解析本地主机。以前有人遇到过这个问题吗?
非常感谢能帮助解决这个问题!
Docker文件
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 日志
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.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
由于 InetAddress.html#getLocalHost
将 "retrieving the name of the host from the system",请确保使用主机名启动容器。
docker run --add-host xxx --hostname yyy
见docker run
Network Settings for --add-host
and --hostname
options
Alpine linux 中可能没有名称服务转换文件,例如 java java.net.InetAddress.getLocalHost 需要一个。
在 dockerfile 中添加这一行
RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' > /etc/nsswitch.conf
我 运行 在 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"