[英]Deploy ASP.Net Application to Window Server Core Container
I'm having an issue with manually building and running a windows server core container with a legacy asp.net web application. 我在使用旧版asp.net Web应用程序手动构建和运行Windows Server核心容器时遇到问题。 From Visual Studio I can run the container with the auto-generated dockerfile/yml file.
从Visual Studio中,我可以使用自动生成的dockerfile / yml文件运行容器。
I want to do a docker build and docker run powershell command using the dockerfile instead of with Visual Studio. 我想使用dockerfile而不是Visual Studio进行docker build和docker run powershell命令。
This is current yml file: 这是当前的yml文件:
version: '3'
services:
fulldotnetwebapplication:
image: fulldotnetwebapplication
build:
context: .\FullDotNetWebApplication
dockerfile: Dockerfile
This is the current dockerfile: 这是当前的dockerfile:
FROM microsoft/aspnet:4.7.1-windowsservercore-ltsc2016
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
Let's say my ASP project is FullDotNetWebApplicationand it contains App_Data, Content, Controllers, etc folders plus Master/ASPX pages along with web/packages/config. 假设我的ASP项目是FullDotNetWebApplication,它包含App_Data,Content,Controllers等文件夹以及Master / ASPX页面以及web / packages / config。
I tried this for my Dockerfile: 我为我的Dockerfile尝试了这个:
FROM microsoft/aspnet:4.7.1-windowsservercore-ltsc2016
WORKDIR /inetpub/wwwroot
COPY . .
COPY ./bin ./bin
and am getting this error: 并收到此错误:
docker : COPY failed: GetFileAttributesEx \\?\C:\Windows\TEMP\docker-builder977521850\bin: The system cannot find the file specified.
At line:1 char:1
+ docker build -t fulldotnetwebapplication .
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (COPY failed: Ge...file specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
What should my docker file look like to deploy this application to IIS from Powershell? 我的docker文件应如何从Powershell将此应用程序部署到IIS? I'm not understanding what magic VS is doing to make this work?
我不明白魔术VS在做什么以使它起作用? Is it building the application or some sort of deployment file being generated?
它是构建应用程序还是生成某种部署文件? Any examples I could be pointed to or sample Dockerfile's would be great.
我可以指出的任何示例或示例Dockerfile都很棒。
These might help get you pointed in the right direction: 这些可能会帮助您指出正确的方向:
https://blog.alexellis.io/run-iis-asp-net-on-windows-10-with-docker/ https://blog.alexellis.io/run-iis-asp-net-on-windows-10-with-docker/
https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-images https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-images
https://www.red-gate.com/simple-talk/sysadmin/virtualization/working-windows-containers-docker-running/ https://www.red-gate.com/simple-talk/sysadmin/virtualization/working-windows-containers-docker-running/
https://sarafian.github.io/2017/02/14/docker-windows-full-asp.net-application.html https://sarafian.github.io/2017/02/14/docker-windows-full-asp.net-application.html
First thing you need to include in your Docker file is a [SHELL] config. 您需要在Docker文件中包括的第一件事是[SHELL]配置。 Check out the Docker PowerShell commands as well
还要检查Docker PowerShell命令
${source:-obj/Docker/publish}
That is why you can run it in VS but not from PowerShell/CMD, VS injects the source part of that path, to map it to the special docker publish folder for the current project. 因此,您可以在VS中运行它,但不能从PowerShell / CMD中运行它,VS会注入该路径的源部分,以将其映射到当前项目的特殊docker publish文件夹。
If up replace that with . .
如果up替换为
. .
. .
, that means copy everything recursively from my current executing directory (which is usually the same as the dockerfile location if you didn't specify the file manually) to the working directory in the container. ,这意味着将所有内容以递归方式从我当前的执行目录(如果未手动指定文件,通常与dockerfile位置相同)复制到容器中的工作目录。 As such, your attempt
COPY ./bin ./bin
is unnecessary, as the proceeding COPY . .
这样,您就不必进行
COPY ./bin ./bin
,因为进行COPY . .
COPY . .
will have already copied that directory (assuming it does actually exist) 将已经复制了该目录(假设它确实存在)
Is it building the application or some sort of deployment file being generated?
它是构建应用程序还是生成某种部署文件?
The container is the unit of deployment, you cannot deploy a container to IIS, it must be run on a container Host. 容器是部署的单元,您不能将容器部署到IIS,它必须在容器主机上运行。 Docker will not build your solution either, before building the container you should build your solution, and then copy just the required output (which is what the VS source path is attempting to do).
Docker也不会构建您的解决方案,在构建容器之前,您应该构建您的解决方案,然后仅复制所需的输出(这是VS源路径正在尝试执行的操作)。
It is possible to get your container workflow to also build your solution using a multi-stage container, where by you use a container with VS installed to build the project, then copy the output to another container for running it, but that is a fairly advanced setup that I wouldn't recommend if you can't even get normal build copying working. 可以使容器工作流也使用多阶段容器来构建解决方案,在这种情况下,您可以使用安装了VS的容器来构建项目,然后将输出复制到另一个容器中以运行它,但这是相当合理的。如果您甚至无法正常进行构建复制,我将不建议您使用高级设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.