Install dotnet core tool Dockerfile

前端 未结 2 1940
梦如初夏
梦如初夏 2021-01-03 08:28

I have an .net core application where I would like to make a SonarBuild inside a container.

So I have a Dockerfile like this:

FROM microsoft/aspnetco         


        
相关标签:
2条回答
  • 2021-01-03 09:09

    As I have read in this thread: https://github.com/dotnet/dotnet-docker/issues/520, we can run a dotnet tool global command inside a container setting the following line:

    ENV PATH="${PATH}:/root/.dotnet/tools"

    So my final Dockerfile is like:

    FROM microsoft/dotnet:2.1-sdk as build-env
    
    WORKDIR /src
    
    COPY question-metrics-api/question-metrics-api.csproj question-metrics-api/
    COPY question-metrics-data/question-metrics-data.csproj question-metrics-data/
    COPY question-metrics-domain/question-metrics-domain.csproj question-metrics-domain/
    COPY tests/question-metrics-domain-tests/question-metrics-domain-tests.csproj tests/question-metrics-domain-tests/
    
    RUN dotnet restore tests/question-metrics-domain-tests
    RUN dotnet restore question-metrics-api/question-metrics-api.csproj
    
    COPY . .
    
    #Run tests
    RUN dotnet test tests/question-metrics-domain-tests/question-metrics-domain-tests.csproj
    
    #Begin Sonar
    RUN dotnet tool install -g dotnet-sonarscanner
    
    ENV PATH="${PATH}:/root/.dotnet/tools"
    
    RUN dotnet sonarscanner begin /k:"question-metrics-api" /d:sonar.host.url="http://sonarqube:9000" /d:sonar.login="7ed84e09a17a31e783fa8522d876e27fe4624977"
    RUN dotnet build
    RUN dotnet sonarscanner end /d:sonar.login="7ed84e09a17a31e783fa8522d876e27fe4624977"
    

    Hope that helps someone!

    0 讨论(0)
  • 2021-01-03 09:32
    FROM microsoft/aspnetcore-build as build-env
    

    That's the issue. Look at the dockerhub page for this: https://hub.docker.com/r/microsoft/aspnetcore-build/. See how it says that it only supports versions 1.1 and 2.0:

    Latest images for 2.1 and newer are now available on microsoft/dotnet. See this link for more details about migrating to 2.1.

    dotnet tool is only available in 2.1 and later. That's why doing RUN dotnet tool install --global dotnet-sonarscanner fails. dotnet doesn't know about a dotnet tool command at all. It tries to look for dotnet-tool in your $PATH, as a fallback, but no such thing exists either.

    You actual fix was:

    FROM microsoft/dotnet:2.1-sdk as build-env
    

    Because this uses the new 2.1 SDK, which does know of the dotnet tool command.

    0 讨论(0)
提交回复
热议问题