从mssql-server docker容器中运行“ dotnet测试”

时间:2018-10-22 12:36:08

标签: .net docker dockerfile

我有一个基于microsoft/dotnet-framework:4.7.2-sdk映像的docker运行在docker中的dotnet构建过程。

还原,生成和发布的工作正常,但是我的集成测试要求在计算机上安装SQL Server。

我想使用多阶段构建在基于dotnet test的容器中运行dotnet xunit(或更具体地说,在我的情况下为microsoft/mssql-server-windows-developer:2017-latest)命令。

但是这样做,我不再可以访问dotnet sdk。在构建的第二阶段如何运行dotnet test

类似这样的方法(不起作用,最后一步失败,因为dotnet命令无法识别):

FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app

# # Copy csproj and restore as distinct layers
COPY ./*.sln ./NuGet.config  ./
COPY ./libs ./libs
COPY ./src ./src

WORKDIR /app/src/Tests/
RUN dotnet build 

FROM microsoft/mssql-server-windows-developer:2017-latest
WORKDIR /app/
COPY --from=build /app/src/Tests/ .
RUN dotnet xunit

1 个答案:

答案 0 :(得分:0)

在尝试安装dotnet生成工具并在'microsoft / mssql-server-windows-developer'映像上运行测试的前提条件进行了几次失败尝试之后,我发现在'microsoft / dotnet-framework'上安装了Sql Server :4.7.2-sdk'图片可能更容易。实际上要容易得多。

尽管我遵循了本指南https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/build-tools-container.md,但实际上在运行测试时遇到了种种麻烦。

但是反过来也行得通。构建需要一些时间,但可以。我的Dockerfile的开头是:

# The 'docker build' command must be run with '-m 4g' argument for sql server.
FROM microsoft/dotnet-framework:4.7.2-sdk

SHELL [ "powershell.exe", "-Command" ]

RUN curl.exe -L -o sql.box https://go.microsoft.com/fwlink/?linkid=840944
RUN curl.exe -L -o sql.exe https://go.microsoft.com/fwlink/?linkid=840945
RUN Start-Process -Wait -FilePath .\sql.exe -ArgumentList /qs, /x:setup
RUN .\setup\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS

ENV MSSQL_IS_RUNNING_IN_DOCKER true

其余只是标准的复制/ dotnet构建/ dotnet测试内容。

相关问题