我正在使用 Docker 创建 Sonarqube 环境,但是当我运行扫描仪时,发生了错误。
我将扫描仪直接运行到容器中:
PS C:\docker\sonarqube\projects\test> docker exec -it sonarqube /bin/bash
sonarqube@05399e4fa8a6:/home/projects/test$ sonar-scanner
信息:扫描仪配置文件:/usr/lib/sonar-scanner/conf/sonar-scanner.properties
信息:项目根配置文件:/home/projects/test/sonar-project.properties
信息:SonarQube Scanner 4.2.0.1873
信息: Java 11.0.3 AdoptOpenJDK(64 位)
信息:Linux 4.9.184-linuxkit amd64
信息:---------------------------- -------------------------------------------------------
信息:执行失败
信息:- -------------------------------------------------- ---------
INFO:总时间:0.364s
INFO:最终内存:2M/10M
INFO:------------ -------------------------------------------------- ----------
错误:SonarQube 扫描仪执行期间出错
java.lang.IllegalStateException:无法
在 org.sonarsource.scanner.api.internal.cache.FileCache.createDir(FileCache.java:147)
处创建用户缓存:/home/.sonar/cache 在 org.sonarsource.scanner.api .internal.cache.FileCache.(FileCache.java:46)
在 org.sonarsource.scanner.api.internal.cache.FileCache.create(FileCache.java:52)
在 org.sonarsource.scanner.api.internal.cache。 FileCacheBuilder.build(FileCacheBuilder.java:48)
在 org.sonarsource.scanner.api.internal.JarDownloaderFactory.create(JarDownloaderFactory.java:42)
在 org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java: 68)
在 org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
在 org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
在 org.sonarsource.scanner.cli.Main.execute (Main.java:73)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
原因:java.nio.file.AccessDeniedException: /home/.sonar/cache
at java.base/sun .nio.fs.UnixException.translateToIOException(Unknown Source)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
在 java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(Unknown Source)
在 java.base/java.nio.file.Files.createDirectory(Unknown Source)
在 java.base/java.nio.file.Files.createAndCheckIsDirectory (Unknown Source)
at java.base/java.nio.file.Files.createDirectories(Unknown Source)
at org.sonarsource.scanner.api.internal.cache.FileCache.createDir(FileCache.java:145)
... 还有 9 个
这是我在 docker-compose 中使用的 dockerfile:
FROM sonarqube:latest
# Switch to root user to be able to install packages.
USER root
# Install packages.
RUN apt-get update
RUN apt-get install -y vim wget
# Install sonarqube scanner.
WORKDIR /usr/src
RUN wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.2.0.1873-linux.zip
RUN unzip sonar-scanner-cli-4.2.0.1873-linux.zip
RUN rm sonar-scanner-cli-4.2.0.1873-linux.zip
RUN mv sonar-scanner-4.2.0.1873-linux /usr/lib/sonar-scanner
# Create symbolic link.
RUN ln -s /usr/lib/sonar-scanner/bin/sonar-scanner /usr/local/bin/sonar-scanner
ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner
ENV SONAR_USER_HOME=/home/.sonar
# Switch back to the sonarqube environment.
WORKDIR $SONARQUBE_HOME
USER sonarqube
码头工人组成:
version: '3.7'
services:
sonarqube:
build: .
container_name: sonarqube
ports:
- 9000:9000
networks:
- sonarnet
environment:
- sonar.jdbc.url=jdbc:postgresql://db:5432/sonar
volumes:
- ./projects:/home/projects
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_extensions:/opt/sonarqube/extensions
db:
image: postgres:latest
container_name: sonarqube_database
networks:
- sonarnet
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
networks:
sonarnet:
driver: bridge
volumes:
projects:
sonarqube_conf:
sonarqube_data:
sonarqube_logs:
sonarqube_extensions:
postgresql:
postgresql_data:
我知道这是一个访问问题,但我不明白为什么。
任何想法为什么会发生这种情况?