安装dotnet核心工具Dockerfile [英] Install dotnet core tool Dockerfile
问题描述
我有一个 .net 核心应用程序,我想在其中创建一个容器内的 SonarBuild.
I have an .net core application where I would like to make a SonarBuild inside a container.
所以我有一个这样的 Dockerfile:
So I have a Dockerfile like this:
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" ]
当我尝试构建此 dockerfile 时出现错误:
When I try to build this dockerfile I got an error:
Step 11/19 : RUN dotnet tool install --global dotnet-sonarscanner
---> Running in 78719975f3b0
No executable found matching command "dotnet-tool"
如何从 aspnetcore-build 镜像安装 dotnet 工具?
How can I install dotnet tool from aspnetcore-build image?
好的,如果我使用基础映像 microsoft/dotnet:2.1-sdk 我不再得到 No executable found matching command "dotnet-tool"
错误,现在我得到 No可执行文件找到匹配命令dotnet-sonarscanner"
Ok, If I use the base image microsoft/dotnet:2.1-sdk I don't get anymore No executable found matching command "dotnet-tool"
error, now I get No executable found matching command "dotnet-sonarscanner"
在这种情况下如何使用 sonarscanner 工具?
How can I use sonarscanner tool in this scenario?
推荐答案
正如我在此线程中所读到的:https://github.com/dotnet/dotnet-docker/issues/520,我们可以在容器内运行 dotnet 工具全局命令,设置以下行:
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"
所以我的最终 Dockerfile 是这样的:
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"
希望对某人有所帮助!
这篇关于安装dotnet核心工具Dockerfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!