首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安装dotnet核心工具Dockerfile

安装dotnet核心工具Dockerfile
EN

Stack Overflow用户
提问于 2018-08-23 10:15:50
回答 2查看 9.2K关注 0票数 4

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

所以我有一个这样的Dockerfile:

代码语言:javascript
复制
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时,我得到了一个错误:

代码语言:javascript
复制
Step 11/19 : RUN dotnet tool install --global dotnet-sonarscanner
 ---> Running in 78719975f3b0
No executable found matching command "dotnet-tool"

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

更新

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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-08-23 19:11:05

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

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

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

代码语言:javascript
复制
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"

希望这对某些人有帮助!

票数 17
EN

Stack Overflow用户

发布于 2018-08-24 09:36:50

代码语言:javascript
复制
FROM microsoft/aspnetcore-build as build-env

这就是问题所在。看看dockerhub的页面:https://hub.docker.com/r/microsoft/aspnetcore-build/。看看它怎么说它只支持1.1和2.0版本:

2.1及更新版本的最新图片现已在微软/dotnet上提供。有关迁移到2.1的更多详细信息,请参阅此链接。

dotnet tool仅在2.1及更高版本中可用。这就是执行RUN dotnet tool install --global dotnet-sonarscanner失败的原因。dotnet根本不知道dotnet tool命令。它试图在您的$PATH中查找dotnet-tool,作为备用,但也不存在这样的东西。

您实际解决的问题是:

代码语言:javascript
复制
FROM microsoft/dotnet:2.1-sdk as build-env

因为它使用了新的2.1SDK,它知道dotnet tool命令。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51977474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档