title: Sonarqube failed to create user cache
body: <p>I'm creating a Sonarqube environment with Docker, but when I run the scanner, an error occurred.  </p>
  
  <p>I run the scanner directly into the container :</p>
  
  <pre><code>PS C:\docker\sonarqube\projects\test&gt; docker exec -it sonarqube /bin/bash
  </code></pre>
  
  <pre><code>sonarqube@05399e4fa8a6:/home/projects/test$ sonar-scanner
  </code></pre>
  
  <blockquote>
    <p>INFO: Scanner configuration file: /usr/lib/sonar-scanner/conf/sonar-scanner.properties<br>
    INFO: Project root configuration file: /home/projects/test/sonar-project.properties<br>
    INFO: SonarQube Scanner 4.2.0.1873<br>
    INFO: Java 11.0.3 AdoptOpenJDK (64-bit)<br>
    INFO: Linux 4.9.184-linuxkit amd64<br>
    INFO: ------------------------------------------------------------------------<br>
    INFO: EXECUTION FAILURE<br>
    INFO: ------------------------------------------------------------------------<br>
    INFO: Total time: 0.364s<br>
    INFO: Final Memory: 2M/10M<br>
    INFO: ------------------------------------------------------------------------<br>
    ERROR: Error during SonarQube Scanner execution<br>
    java.lang.IllegalStateException: Unable to create user cache: /home/.sonar/cache<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.internal.cache.FileCache.createDir(FileCache.java:147)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.internal.cache.FileCache.(FileCache.java:46)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.internal.cache.FileCache.create(FileCache.java:52)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.internal.cache.FileCacheBuilder.build(FileCacheBuilder.java:48)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.internal.JarDownloaderFactory.create(JarDownloaderFactory.java:42)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:68)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.cli.Main.execute(Main.java:73)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.cli.Main.main(Main.java:61)<br>
    Caused by: java.nio.file.AccessDeniedException: /home/.sonar/cache<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at java.base/sun.nio.fs.UnixException.translateToIOException(Unknown Source)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(Unknown Source)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at java.base/java.nio.file.Files.createDirectory(Unknown Source)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at java.base/java.nio.file.Files.createAndCheckIsDirectory(Unknown Source)<br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       at java.base/java.nio.file.Files.createDirectories(Unknown Source)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        at org.sonarsource.scanner.api.internal.cache.FileCache.createDir(FileCache.java:145)<br>
            ... 9 more</p>
  </blockquote>
  
  <p>Here is the dockerfile I use in a docker-compose :</p>
  
  <pre><code>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  
  </code></pre>
  
  <p>The docker-compose :</p>
  
  <pre><code>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:
  
  </code></pre>
  
  <p>I understand that's an access problem, but I don't understand why.<br>
  Any ideas why is that happen ?</p>