Docker Alpine and sonar-scanner "java.lang.IllegalStateException: java.io.IOException: Cannot run program"

Hi, I have a problem running sonar-scanner on a docker image. Namely when trying to scan it throws an error.

git clone GitHub - MateuszMiekicki/honeybadger

cd honeybadger/

cmake -Bbuild -G Ninja

cmake --build build


INFO: Scanner configuration file: /opt/sonar-scanner-4.6.2.2472/conf/sonar-scanner.properties

INFO: Project root configuration file: /honeybadger/sonar-project.properties

INFO: SonarScanner 4.6.2.2472

INFO: Java 11.0.13 Alpine (64-bit)

INFO: Linux 5.10.60.1-microsoft-standard-WSL2 amd64

INFO: User cache: /root/.sonar/cache

INFO: Scanner configuration file: /opt/sonar-scanner-4.6.2.2472/conf/sonar-scanner.properties

INFO: Project root configuration file: /honeybadger/sonar-project.properties

INFO: Analyzing on SonarCloud

INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)

INFO: Load global settings

INFO: Load global settings (done) | time=276ms

INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu

INFO: User cache: /root/.sonar/cache

INFO: Load/download plugins

INFO: Load plugins index

INFO: Load plugins index (done) | time=87ms

INFO: Load/download plugins (done) | time=325ms

INFO: Loaded core extensions: developer-scanner

INFO: Load project settings for component key: 'MateuszMiekicki_honeybadger'

INFO: Load project settings for component key: 'MateuszMiekicki_honeybadger' (done) | time=61ms

INFO: Process project properties

INFO: Execute project builders

INFO: Execute project builders (done) | time=2ms

INFO: Project key: MateuszMiekicki_honeybadger

INFO: Base dir: /honeybadger

INFO: Working dir: /honeybadger/.scannerwork

INFO: Load project branches

INFO: Load project branches (done) | time=66ms

INFO: Check ALM binding of project 'MateuszMiekicki_honeybadger'

INFO: Detected project binding: BOUND

INFO: Check ALM binding of project 'MateuszMiekicki_honeybadger' (done) | time=52ms

INFO: Load project pull requests

INFO: Load project pull requests (done) | time=54ms

INFO: Load branch configuration

INFO: Load branch configuration (done) | time=2ms

INFO: Load quality profiles

INFO: Load quality profiles (done) | time=90ms

INFO: Load active rules

INFO: Load active rules (done) | time=2249ms

INFO: Organization key: github-honeybadger

INFO: Load project repositories

INFO: Load project repositories (done) | time=56ms

INFO: Indexing files...

INFO: Project configuration:

INFO:   Excluded sources: **/build-wrapper-dump.json

INFO: 7 files indexed

INFO: 0 files ignored because of inclusion/exclusion patterns

INFO: 0 files ignored because of scm ignore settings

INFO: Quality profile for cpp: Sonar way

INFO: ------------- Run sensors on module honeybadger

INFO: Load metrics repository

INFO: Load metrics repository (done) | time=61ms

INFO: Sensor C# Project Type Information [csharp]

INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms

INFO: Sensor C# Analysis Log [csharp]

INFO: Sensor C# Analysis Log [csharp] (done) | time=18ms

INFO: Sensor C# Properties [csharp]

INFO: Sensor C# Properties [csharp] (done) | time=0ms

INFO: Sensor HTML [web]

INFO: Sensor HTML [web] (done) | time=4ms

INFO: Sensor VB.NET Project Type Information [vbnet]

INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms

INFO: Sensor VB.NET Analysis Log [vbnet]

INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=17ms

INFO: Sensor VB.NET Properties [vbnet]

INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms

INFO: Sensor JaCoCo XML Report Importer [jacoco]

INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml

INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer

INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=6ms

INFO: Sensor CSS Rules [javascript]

INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.

INFO: Sensor CSS Rules [javascript] (done) | time=1ms

INFO: Sensor ThymeLeaf template sensor [securityjavafrontend]

INFO: Sensor ThymeLeaf template sensor [securityjavafrontend] (done) | time=1ms

INFO: Sensor Serverless configuration file sensor [security]

INFO: 0 Serverless function entries were found in the project

INFO: 0 Serverless function handlers were kept as entrypoints

INFO: Sensor Serverless configuration file sensor [security] (done) | time=8ms

INFO: Sensor AWS SAM template file sensor [security]

INFO: Sensor AWS SAM template file sensor [security] (done) | time=2ms

INFO: Sensor CFamily [cpp]

INFO: CFamily plugin version: 6.28.0.39490

INFO: Using compile commands: /honeybadger/build/compile_commands.json

INFO: Available processors: 12

INFO: Using 1 thread for analysis according to value of "sonar.cfamily.threads" property.

INFO: Cache is explicitly disabled: Optional[false]

INFO: ------------------------------------------------------------------------

INFO: EXECUTION FAILURE

INFO: ------------------------------------------------------------------------

INFO: Total time: 11.037s

INFO: Final Memory: 30M/107M

INFO: ------------------------------------------------------------------------

ERROR: Error during SonarScanner execution

java.lang.IllegalStateException: java.io.IOException: Cannot run program "/honeybadger/.scannerwork/.sonartmp/36667999123322702/subprocess" (in directory "/honeybadger/build"): error=2, No such file or directory

        at com.sonar.cpp.driver.ProcessExecutor.execute(ProcessExecutor.java:74)

        at com.sonar.cpp.driver.ProcessExecutor.execute(ProcessExecutor.java:45)

        at com.sonar.cpp.analyzer.ClangDriver.lambda$probeCompiler$12(ClangDriver.java:614)

        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)

        at com.sonar.cpp.analyzer.ClangDriver.probeCompiler(ClangDriver.java:604)

        at com.sonar.cpp.analyzer.ClangDriver.onCapture(ClangDriver.java:357)

        at com.sonar.cpp.analyzer.CompilerDrivers.onCapture(CompilerDrivers.java:34)

        at com.sonar.cpp.plugin.CFamilySensor.lambda$process$12(CFamilySensor.java:628)

        at com.sonar.cpp.plugin.CompileCommandsReader.readCaptures(CompileCommandsReader.java:41)

        at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:625)

        at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:412)

        at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:181)

        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:62)

        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)

        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)

        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)

        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)

        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)

        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:440)

        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:436)

        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:394)

        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)

        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)

        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)

        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)

        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)

        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)

        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)

        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.base/java.lang.reflect.Method.invoke(Method.java:566)

        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)

        at com.sun.proxy.$Proxy0.execute(Unknown Source)

        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)

        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)

        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)

        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)

        at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Caused by: java.io.IOException: Cannot run program "/honeybadger/.scannerwork/.sonartmp/36667999123322702/subprocess" (in directory "/honeybadger/build"): error=2, No such file or directory

        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)

        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)

        at com.sonar.cpp.driver.ProcessExecutor.execute(ProcessExecutor.java:58)

        ... 39 more

Caused by: java.io.IOException: error=2, No such file or directory

        at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)

        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)

        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)

        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)

        ... 41 more

ERROR:

ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

The errors I get. Surprisingly on Windows it works(my default machine).

Hi @0xd00d2bad and welcome to the community :wave:

are you using our official scanner docker image (sonarsource/sonar-scanner-cli) ? if yes than you should be aware of this warning that is displayed on the docker hub page as well as on our git repo for the image:

Warning: These Docker images are not compatible with C/C++/Objective-C projects.

you will need to build your own image that includes all your required build dependencies and you probably want to check out our documentation about analyzing c-family languages here.

hope that helps :slight_smile:

Sorry, I forgot to mention this. I created my own image based on Linux Alpine (honeybadger/.docker at master · MateuszMiekicki/honeybadger · GitHub) and made it available on docker hub(Docker Hub). If there is something that would make the problem easier to solve please mention it.

Hi @0xd00d2bad ,

we may not be compatible with alpine linux. Would you be able to test with a different distribution? i.e. debian or ubuntu?

Yeah, sure. Do you happen to know why it doesn’t work? Or at least a guess? Any advice would be helpful.
I will upload the result of creating another image tonight.
Another question like this. Is there any way which you recommend to build, test and analyze (with sonar-scanner) a project in docker?

Thank you for your time.

Okey, I created a new image based on ubuntu:22.04 and it generally works, although I have one “but”, it takes 500 megabytes more, which is a horrendous amount at two gigabytes total.

FROM ubuntu:22.04

RUN apt-get update && \
    apt-get install -y cmake && \
    apt-get install -y ninja-build && \
    apt-get install -y g++-11 && \
    update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11 && \
    apt-get install -y doxygen && \
    apt-get install -y git && \
    apt-get install -y wget && \
    apt-get install -y unzip

ARG cmake_generator=Ninja

#Downloading, building and installing google test.
ARG google_test_tag=release-1.11.0
ARG google_test_repo=https://github.com/google/googletest.git
ARG googletest_dir=googletest
RUN git clone --depth 1 \
    --branch $google_test_tag \
    $google_test_repo && \
    cd $googletest_dir && \
    cmake -Bbuild -G $cmake_generator && \
    cmake --build build --target install

#Downloading, building and installing google benchmark.
#note: The google benchamrk tag will be up for change
# when the next version is released.
# The reason is incompatibility of branchy names
# in dependencies(google test moved from master to main).
ARG google_benchmark_tag=main
ARG google_benchmark_repo=https://github.com/google/benchmark.git
ARG google_benchmark_dir=benchmark
RUN git clone --depth 1 \
    --branch $google_benchmark_tag \
    $google_benchmark_repo && \
    cd $google_benchmark_dir && \
    cmake -Bbuild -G $cmake_generator \
    -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on \
    -DCMAKE_BUILD_TYPE=Release && \
    cmake --build build --target install --config Release

#Downloading, building and installing opencv.
ARG opencv_test_tag=4.5.4
ARG opencv_test_repo=https://github.com/opencv/opencv.git
ARG opencv_dir=opencv
RUN git clone --depth 1 \
    --branch $opencv_test_tag \
    $opencv_test_repo && \
    cd $opencv_dir && \
    cmake -Bbuild -G $cmake_generator -DCMAKE_BUILD_TYPE=Release && \
    cmake --build build --target install --config Release
#install sonar scanner
COPY install-sonar-scanner.sh /install-sonar-scanner.sh
RUN chmod +x install-sonar-scanner.sh
RUN ./install-sonar-scanner.sh

#Clean
RUN rm -r $googletest_dir && \
    rm -r $google_benchmark_dir && \
    rm -r $opencv_dir && \
    apt-get autoremove && \
    apt-get autoclean && \
    apt-get clean
#!/bin/sh
set -eux

SONAR_SCANNER_VERSION=4.6.2.2472

# Only install java if not already present (to avoid conflicting Java version)
arg_java=""
if ! which java >/dev/null; then
  arg_java=default-jre
fi

apt-get install -y $arg_java

mkdir -p /opt
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}.zip -O /opt/sonar-scanner.zip
unzip /opt/sonar-scanner.zip -d /opt
rm /opt/sonar-scanner.zip
ln -s /opt/sonar-scanner-${SONAR_SCANNER_VERSION}/bin/sonar-scanner /usr/bin/sonar-scanner

Both things work when the post is published.

Hi @0xd00d2bad,

I would use ubuntu 20.04 which is LTS and the version usually used in CI.

It’s definitely a better choice, but it doesn’t have gcc-11 “doymindedly”. Generally not sure why it doesn’t work on Alpine?
Oh and thank you for your time.