簡體   English   中英

從mssql-server docker容器中運行“ dotnet測試”

[英]Running “dotnet test” from within a mssql-server docker container

我有一個基於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

在嘗試嘗試安裝dotnet生成工具並在“ microsoft / mssql-server-windows-developer”映像上運行測試的前提條件進行了幾次失敗嘗試之后,我發現在“ microsoft / dotnet-framework:4.7”上安裝了Sql Server。 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測試內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM