简体   繁体   English

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

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

I have a dotnet build process running in docker based on the microsoft/dotnet-framework:4.7.2-sdk image. 我有一个基于microsoft/dotnet-framework:4.7.2-sdk映像在docker中运行的dotnet构建过程。

Restore, build and publish works as expected, but my integration tests require SQL Server to be installed on the machine. 还原,生成和发布的工作符合预期,但是我的集成测试要求在计算机上安装SQL Server。

I would like to use a multistage build to run the dotnet test (or more specifically in my case dotnet xunit ) command within a container based on microsoft/mssql-server-windows-developer:2017-latest . 我想使用多阶段构建在基于microsoft/mssql-server-windows-developer:2017-latest的容器中运行dotnet test (或更具体地,在我的情况下为dotnet xunit )命令。

But doing that I no longer have access to the dotnet sdk. 但是这样做之后,我将无法再访问dotnet sdk。 How can I run dotnet test from the second stage of my build. 从构建的第二阶段开始如何运行dotnet test

Some like this (not working, the last step fails, because the dotnet command is not recognized): 像这样的一些(不起作用,最后一步失败,因为未识别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

After several unsuccessful attempts of trying to install the dotnet build tools and prerequisites for running the tests on the 'microsoft/mssql-server-windows-developer' image, I found that installing Sql Server on the `microsoft/dotnet-framework:4.7.2-sdk' image was probably easier. 在尝试尝试安装dotnet生成工具并在“ microsoft / mssql-server-windows-developer”映像上运行测试的前提条件进行了几次失败尝试之后,我发现在“ microsoft / dotnet-framework:4.7”上安装了Sql Server。 2 SDK的图像可能更容易。 A lot easier actually. 实际上要容易得多。

Though I followed this guide https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/build-tools-container.md is ran in to all kinds of trouble actually running the tests. 尽管我遵循了本指南,但https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/build-tools-container.md实际在运行测试时会遇到各种麻烦。

But the other way around works. 但是反之亦然。 Build takes some time, but it works. 构建需要一些时间,但可以。 The start of my Dockerfile is: 我的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

The rest is just standard copy/dotnet build/dotnet test stuff. 剩下的只是标准的复制/ dotnet构建/ dotnet测试内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CS0016 在服务器核心 Docker EE 容器中运行时使用带有 --output 参数的 dotnet build/publish - CS0016 using dotnet build/publish with --output parameter when running in Server Core Docker EE container 在 docker 容器中运行 dotnet watch 会破坏 Nuget package 参考 - Running dotnet watch run in docker container breaks Nuget package references 在 Docker 容器中运行 do.net 6 应用程序时出现不变文化问题 - Invariant culture issue while running the dotnet 6 application in a Docker Container Do.net docker 容器 - Dotnet docker container Do.net 构建权限在运行 Jenkins 的 Docker 容器中被拒绝 - Dotnet build permission denied in Docker container running Jenkins 以非 root 身份运行时无法在 docker 容器中运行 dotnet 测试 - Unable to run dotnet test in docker container when run as non root 由于相对路径,在 Docker 容器中运行 dotnet 在 Linux 上失败 - Running dotnet in a Docker container fails on Linux because of relative path 使用命名管道从容器内部访问 docker 引擎时出现 Docker.Do.net UnauthorizedAccessException - Docker.Dotnet UnauthorizedAccessException when accessing docker engine from inside a container using named pipes 从在 Docker Windows 容器中运行的 .Net 4.8 控制台应用程序连接到本地 SQL Server - Connect to local SQL Server from .Net 4.8 Console Application Running in Docker Windows container 如何从 windows Z05B6053C415A2134EAD6 容器中的 .NET 应用程序连接到在主机上运行的 SQL 服务器 - How do you connect to SQL Server running on the host from a .NET app in a windows docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM