打包一个传统的ASP.NET web app作为Docker镜像
(1)针对NerdDinner应用的Dockerfile内容如下
PS E:\DockeronWindows\Chapter02\ch02-nerd-dinner> cat .\Dockerfile
# escape=`
FROM sixeyed/msbuild:netfx-4.5.2-webdeploy-10.0.14393.1198 AS builderWORKDIR C:\src\NerdDinner
COPY src\NerdDinner\packages.config .
RUN nuget restore packages.config -PackagesDirectory ..\packagesCOPY src C:\src
RUN msbuild NerdDinner.csproj /p:OutputPath=c:\out\NerdDinner `
/p:DeployOnBuild=true /p:VSToolsPath=C:\MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0.3\tools\VSToolsPath# app image
FROM microsoft/aspnet:windowsservercore-10.0.14393.1198
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]ENV BING_MAPS_KEY bing_maps_key
WORKDIR C:\nerd-dinnerRUN Remove-Website -Name 'Default Web Site'; `
New-Website -Name 'nerd-dinner' `
-Port 80 -PhysicalPath 'c:\nerd-dinner' `
-ApplicationPool '.NET v4.5'RUN & c:\windows\system32\inetsrv\appcmd.exe `
unlock config `
/section:system.webServer/handlersCOPY --from=builder C:\out\NerdDinner\_PublishedWebsites\NerdDinner C:\nerd-dinner
(2)进行构建镜像
PS E:\DockeronWindows\Chapter02\ch02-nerd-dinner> docker container run -d -P dockeronwindows/ch02-nerd-dinner
(3)通过docker container inspect获得容器的IP地址
(4)访问服务应该如下所示:
docker container run -d -P dockeronwindows/ch02-nerd-dinner