我有一个.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" ]当我尝试构建这个dockerfile时,我得到了一个错误:
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工具?
发布于 2018-08-23 19:11:05
正如我在这个线程中读到的: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"希望这对某些人有帮助!
发布于 2018-08-24 09:36:50
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,作为备用,但也不存在这样的东西。
您实际解决的问题是:
FROM microsoft/dotnet:2.1-sdk as build-env因为它使用了新的2.1SDK,它知道dotnet tool命令。
https://stackoverflow.com/questions/51977474
复制相似问题