简体   繁体   English

没有错误时如何调试Docker映像中的问题

[英]How to debug issues in docker image when there is no error

I am building a ASP.NET web API application running on .net framework 4.5. 我正在构建在.net Framework 4.5上运行的ASP.NET Web API应用程序。 Here is my docker file: 这是我的docker文件:

FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
COPY TestWebAPI/*.csproj ./TestWebAPI/
COPY TestWebAPI/*.config ./TestWebAPI/
RUN nuget restore

# copy everything else and build app
COPY TestWebAPI/. ./TestWebAPI/
WORKDIR /app/TestWebAPI
RUN msbuild /p:Configuration=Release


FROM microsoft/iis:10.0.14393.206

SHELL ["powershell"]

WORKDIR /inetpub/wwwroot
COPY --from=build /app/TestWebAPI/. ./

RUN Remove-Website -Name 'Default Web Site'
RUN New-Website -Name 'TestWebApi' -Port 80 \
    -PhysicalPath 'c:\inetpub\wwwroot' -ApplicationPool '.NET v4.5'
EXPOSE 80

CMD Write-Host IIS Started... ; \
    while ($true) { Start-Sleep -Seconds 3600 }

Then i Run following commands: 然后我运行以下命令:

 docker image build --tag v7 --file .\Dockerfile .
 docker container run --detach --publish 80 v7
docker ps to get the port number

When I go to specific port, the site does not load. 当我转到特定端口时,该站点无法加载。 There was no error while building containers. 构建容器时没有错误。 How can I find the issue (obviously its my docker file) 我如何找到问题(显然是我的docker文件)

The command that is executed when running the container is 运行容器时执行的命令是

CMD Write-Host IIS Started... ; \
    while ($true) { Start-Sleep -Seconds 3600 }

This obviously does not start the website as the steps executed with the RUN command are only executed during build time of the image. 显然,这不会启动网站,因为使用RUN命令执行的步骤仅在映像的构建期间执行。

I guess you meant to also execute the two steps executed within the build phase of the container with the RUN command. 我想您还打算使用RUN命令执行在容器的构建阶段中执行的两个步骤。 This can by achieved by either chaining them within the CMD step of the Dockerfile or by creating a small script wrapping these commands and executing it. 这可以通过在Dockerfile的CMD步骤中链接它们或通过创建一个包装这些命令并执行的小脚本来实现。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM