sonarqube scanner::无法访问docker中的sonarqube服务

mqkwyuun  于 2023-05-06  发布在  Docker
关注(0)|答案(2)|浏览(383)

我想通过docker学习sonarqube。下面是docker-compose.yml文件。我使用ipv4localhostsonarqube容器IP,但我每次都得到以下错误。我在这里分享所有的代码。我做错了什么?

version: '3'

services:
  sonarqube:
    image: sonarqube:latest
    ports:
      - "9000:9000"
    networks:
      - sonarnet
    environment:
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=sonar
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_logs:/opt/sonarqube/logs
      - sonarqube_extensions:/opt/sonarqube/extensions
    depends_on:
      - db

  db:
    image: postgres:latest
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
      - POSTGRES_DB=sonar
    volumes:
      - postgresql:/var/lib/postgresql
    networks:
      - sonarnet

  sonarscanner:
    image: sonarsource/sonar-scanner-cli
    volumes:
      - ./payment-and-transaction:/usr/src
    environment:
      - SONAR_PROJECT_KEY=payment-and-transaction
      - SONAR_HOST_URL=http://localhost:9000
      - SONAR_LOGIN="xxxxxxxxxxxxxxxxxx"
    networks:
      - sonarnet

volumes:
  sonarqube_data:
  sonarqube_logs:
  sonarqube_extensions:
  postgresql:

networks:
  sonarnet:

下面是我的错误日志

sonarscanner_1  | ERROR: SonarQube server [http://localhost:9000] can not be reached
sonarscanner_1  | INFO: ------------------------------------------------------------------------
sonarscanner_1  | INFO: EXECUTION FAILURE
sonarscanner_1  | INFO: ------------------------------------------------------------------------
sonarscanner_1  | INFO: Total time: 2.387s
sonarscanner_1  | INFO: Final Memory: 3M/17M
sonarscanner_1  | INFO: ------------------------------------------------------------------------
sonarscanner_1  | ERROR: Error during SonarScanner execution
sonarscanner_1  | org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
sonarscanner_1  |   at java.base/java.security.AccessController.doPrivileged(Native Method)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
sonarscanner_1  |   at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
sonarscanner_1  |   at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
sonarscanner_1  |   at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
sonarscanner_1  |   at org.sonarsource.scanner.cli.Main.main(Main.java:62)
sonarscanner_1  | Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
sonarscanner_1  |   ... 7 more
sonarscanner_1  | Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:265)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connect(RealConnection.java:183)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Transmitter.newExchange(Transmitter.java:169)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
sonarscanner_1  |   ... 10 more
sonarscanner_1  | Caused by: java.net.ConnectException: Connection refused (Connection refused)
sonarscanner_1  |   at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
sonarscanner_1  |   at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
sonarscanner_1  |   at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
sonarscanner_1  |   at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
sonarscanner_1  |   at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
sonarscanner_1  |   at java.base/java.net.Socket.connect(Socket.java:609)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.platform.Platform.connectSocket(Platform.java:130)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:263)
sonarscanner_1  |   ... 31 more
sonarscanner_1  | ERROR: 
sonarscanner_1  | ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

我使用下面的命令来运行这一切

docker-compose up
ckocjqey

ckocjqey1#

你的设置有问题,我会一行一行的复制,你可以自己添加docker-compose

docker pull sonarqube

第二,让你的人脉

docker network create sonarnet

然后,db

docker run -d --name sonar-db --network sonarnet -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -e POSTGRES_DB=sonar postgres:9.6

在最后

docker run -d --name sonar -p 9000:9000 --network sonarnet -e SONARQUBE_JDBC_URL=jdbc:postgresql://sonar-db:5432/sonar -e SONAR_JDBC_USERNAME=sonar -e SONAR_JDBC_PASSWORD=sonar sonarqube

检查您的http://localhost:9000/
admin/admin,您应该可以登录。

试试这个sonarsource

docker run \\
    --rm \\
    -e SONAR_HOST_URL="http://localhost:9000/" \\
    -e SONAR_LOGIN="yourToken" \\
    -v "${YOUR_REPO}:/home/dir/src" \\
    sonarsource/sonar-scanner-cli
yhxst69z

yhxst69z2#

我认为您的sonarscanner容器中的SONAR_HOST_URL=http://localhost:9000存在问题,因为您的容器无法通过localhost访问本地计算机上运行的进程,因为localhost将引用您的容器,而不是您的计算机,因此您不能使用localhost:9000,而是使用sonarqube:9000通过容器访问或使用host.docker.internal:9000通过本地计算机访问

相关问题