【发布时间】:2020-03-11 04:50:54
【问题描述】:
我正在尝试将 Sonarqube 与 CloudRun 一起使用,为此我需要在启动 docker 映像时支持使用环境变量 PORT。所以我试图“扩展”我的Dockerfile,比如:
FROM sonarqube:7.9-community
WORKDIR $SONARQUBE_HOME
COPY sonar.properties $SONARQUBE_HOME
COPY run.sh ./bin/
EXPOSE 8080
ENTRYPOINT ["./bin/run.sh"]
我修改了 sonar.properties 以包含如下一行:
sonar.web.port=__PORT__
然后我将run.sh修改为:
sed "s/__PORT__/$PORT/g" ./sonar.properties > conf/sonar.properties
并尝试像这样启动服务器:
docker run -e PORT=8080 sonarqube-custom
日志显示没有错...
2019.11.15 02:55:04 INFO web[][o.s.s.q.ProjectsInWarningDaemon] Counting number of projects in warning is enabled.
2019.11.15 02:55:04 INFO web[][o.s.s.p.p.PlatformLevelStartup] Running Community Edition
2019.11.15 02:55:04 INFO web[][o.s.s.p.Platform] WebServer is operational
2019.11.15 02:55:04 INFO app[][o.s.a.SchedulerImpl] Process[web] is up
2019.11.15 02:55:04 INFO app[][o.s.a.ProcessLauncherImpl] Launch process[[key='ce', ipcIndex=3, logFilenamePrefix=ce]] from [/opt/sonarqube]: /usr/local/openjdk-11/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube/temp --add-opens=java.base/java.util=ALL-UNNAMED -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp ./lib/common/*:/opt/sonarqube/lib/jdbc/h2/h2-1.3.176.jar org.sonar.ce.app.CeServer /opt/sonarqube/temp/sq-process3988720795271274831properties
2019.11.15 02:55:04 INFO web[][o.s.s.q.ProjectsInWarningDaemon] Counting number of projects in warning will be disabled as there are no more projects in warning.
2019.11.15 02:55:05 INFO ce[][o.s.p.ProcessEntryPoint] Starting ce
2019.11.15 02:55:05 INFO ce[][o.s.ce.app.CeServer] Compute Engine starting up...
2019.11.15 02:55:06 INFO ce[][o.e.p.PluginsService] no modules loaded
2019.11.15 02:55:06 INFO ce[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2019.11.15 02:55:06 INFO ce[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2019.11.15 02:55:06 INFO ce[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019.11.15 02:55:07 INFO ce[][o.s.s.e.EsClientProvider] Connected to local Elasticsearch: [127.0.0.1:9001]
2019.11.15 02:55:07 INFO ce[][o.sonar.db.Database] Create JDBC data source for jdbc:h2:tcp://127.0.0.1:9092/sonar
2019.11.15 02:55:07 WARN ce[][o.s.db.dialect.H2] H2 database should be used for evaluation purpose only.
2019.11.15 02:55:08 INFO ce[][o.s.s.p.ServerFileSystemImpl] SonarQube home: /opt/sonarqube
2019.11.15 02:55:08 INFO ce[][o.s.c.c.CePluginRepository] Load plugins
2019.11.15 02:55:10 INFO ce[][o.s.c.c.ComputeEngineContainerImpl] Running Community edition
2019.11.15 02:55:10 INFO ce[][o.s.ce.app.CeServer] Compute Engine is operational
2019.11.15 02:55:10 INFO app[][o.s.a.SchedulerImpl] Process[ce] is up
2019.11.15 02:55:10 INFO app[][o.s.a.SchedulerImpl] SonarQube is up
但是当我尝试访问 URL localhost:8080 时失败了
【问题讨论】:
-
你在使用 MACos 作为声纳容器吗?
-
如果您以
docker run -e PORT=8080 sonarqube-custom启动您的容器,您将无法联系localhost:8080上的任何内容,因为您还没有发布任何端口(例如使用-p选项到@ 987654334@). -
@ThanhNguyenVan 是的,我现在在 Mac 上
-
Sonarqube 使用默认端口:9000,你能分享
run.sh文件吗? -
尝试
docker run -p "8080:8080" -e PORT=8080sonarqube-custom,它会将主机8080发布到容器8080。我认为,您不需要更改并添加sonar.web.port=__PORT__,让sonarqube监听任何端口并发布特定主机端口到容器。