安装dotnet核心工具Dockerfile

Raf*_*eli 3 docker .net-core

我有一个.net核心应用程序,我想在一个容器内创建SonarBuild。

所以我有一个像这样的Dockerfile:

FROM microsoft/aspnetcore-build 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 --global dotnet-sonarscanner
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"
#End Sonar

RUN dotnet publish question-metrics-api/question-metrics-api.csproj -c Release -o publish

FROM microsoft/aspnetcore as runtime-env

COPY --from=build-env src/question-metrics-api/publish .
EXPOSE 80
ENTRYPOINT [ "dotnet", "question-metrics-api.dll" ]
Run Code Online (Sandbox Code Playgroud)

当我尝试构建此dockerfile时出现错误:

Step 11/19 : RUN dotnet tool install --global dotnet-sonarscanner
 ---> Running in 78719975f3b0
No executable found matching command "dotnet-tool"
Run Code Online (Sandbox Code Playgroud)

如何从aspnetcore-build映像安装dotnet工具?

更新资料

好的,如果我使用基本映像microsoft / dotnet:2.1-sdk,我不会再No executable found matching command "dotnet-tool"出现错误,现在我得到了No executable found matching command "dotnet-sonarscanner"

在这种情况下如何使用sonarscanner工具?

Raf*_*eli 7

正如我在该线程中所读的:https : //github.com/dotnet/dotnet-docker/issues/520,我们可以在容器内运行dotnet工具全局命令,并设置以下行:

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

所以我最终的Dockerfile是这样的:

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"
Run Code Online (Sandbox Code Playgroud)

希望能对某人有所帮助!