Search code examples
docker.net-coresonarqube

How to pass dotnet tools in to a docker


On root I used : dotnet tool install --global dotnet-sonarscanner --version 4.7.1to install sonarscanner and it's working:

SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
WARNING: Please specify the command 'begin' or 'end' to indicate whether pre- or post-processing is required. These parameters will become mandatory in a later release.
Post-processing started.

But in a docker it isn't:

root@3bea636a6418:/# dotnet sonarscanner
bash: dotnet: command not found

I tried to pass it:

export PATH="$PATH:/root/.dotnet/tools"

but with no luck

ps. ...and everything because of sonarscanner could not find java on docker:

SonarScanner for MSBuild 5.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI…
Could not find ‘java’ executable in JAVA_HOME or PATH.
The SonarScanner did not complete successfully
14:43:39.402 Post-processing failed. Exit code: 1
Cleaning up file based variables
ERROR: Job failed: exit code 1```

Solution

  • Install all the dependencies for your dotnet tools to work, ldd command can help you with this, and make sure all software required can be found also, for example can be found on the PATH variable if required.

    to help you use interactive bash on the docker container, and add to your dockerfile if this works. docker exec -it (container) bash

    docker images usually installs what is required only, so you add the tools only to run your software successfully.