gpt4 book ai didi

docker - Sonarqube无法创建用户缓存

转载 作者:行者123 更新时间:2023-12-02 19:20:29 24 4
gpt4 key购买 nike

我正在使用Docker创建Sonarqube环境,但是当我运行扫描程序时,发生了错误。

我将扫描仪直接运行到容器中:

PS C:\docker\sonarqube\projects\test> docker exec -it sonarqube /bin/bash
sonarqube@05399e4fa8a6:/home/projects/test$ sonar-scanner

INFO: Scanner configuration file: /usr/lib/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/projects/test/sonar-project.properties
INFO: SonarQube Scanner 4.2.0.1873
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 4.9.184-linuxkit amd64
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.364s
INFO: Final Memory: 2M/10M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Unable to create user cache: /home/.sonar/cache
       at org.sonarsource.scanner.api.internal.cache.FileCache.createDir(FileCache.java:147)
       at org.sonarsource.scanner.api.internal.cache.FileCache.(FileCache.java:46)
       at org.sonarsource.scanner.api.internal.cache.FileCache.create(FileCache.java:52)
       at org.sonarsource.scanner.api.internal.cache.FileCacheBuilder.build(FileCacheBuilder.java:48)
       at org.sonarsource.scanner.api.internal.JarDownloaderFactory.create(JarDownloaderFactory.java:42)
       at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:68)
       at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
       at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
       at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
       at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: 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)
       at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(Unknown Source)
       at java.base/java.nio.file.Files.createDirectory(Unknown Source)
       at 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 more



这是我在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

docker-compose:
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:


我知道这是访问问题,但我不明白为什么。
任何想法为什么会这样?

最佳答案

解决了我的问题。在dockerfile中:

RUN mkdir /home/.sonar
RUN chmod 777 /home/.sonar
ENV SONAR_USER_HOME=/home/.sonar

关于docker - Sonarqube无法创建用户缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60268228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com