【问题标题】:Running "dotnet test" from within a mssql-server docker container从 mssql-server docker 容器中运行“dotnet test”
【发布时间】:2018-10-22 12:36:08
【问题描述】:

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

按预期恢复、构建和发布工作,但我的集成测试需要在计算机上安装 SQL Server。

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

但是这样做我不再可以访问 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

【问题讨论】:

    标签: .net docker dockerfile


    【解决方案1】:

    在尝试安装 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 测试的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-13
      • 1970-01-01
      • 2019-08-28
      • 2022-06-24
      • 1970-01-01
      • 1970-01-01
      • 2022-08-10
      • 1970-01-01
      相关资源
      最近更新 更多