无法从浏览器访问IIS容器 - Docker

问题描述 投票:0回答:2

Windows版本:Windows Server 2016

Docker for Windows版本:18.09.0

image

我尝试按照https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-images中的步骤进行操作

我在c:\ Build上有一个Docker文件:

FROM microsoft/iis
RUN echo "Hello World - Dockerfile" > c:\inetpub\wwwroot\index.html

请注意,我也尝试过使用FROM microsoft/iis:10.0.14393.206

所以,我使用PowerShell运行管理员权限:

docker build -t imagename c:\Build

然后我跑了:

docker run -d -p 8000:80 --name container imagename ping -t localhost

enter image description here

以上所有步骤都没问题,但我无法访问该网站,

我尝试了各种组合,如:ipconfig的IP地址:8000或80;来自inspect的IP地址:8000 / 80.请注意我也设置了防火墙以允许端口8000

enter image description here

但一切都失败了。

然后,我去了互联网,发现我实际上可以打电话给bash。因此,我运行了exec,然而,发生了一些奇怪的事情:

enter image description here

我不确定这是否意味着容器不工作?但检查和容器ls表明它应该工作。

fyi网络:enter image description here

检查容器:enter image description here enter image description here enter image description here

我真的找不到任何来自互联网的解决方案

任何建议都会有所帮助,谢谢

docker iis windows-server-2016
2个回答
1
投票

更新:我使用下面的配置和远程IIS访问。确保防火墙没有阻止本地IP的docker。此外,在我们的案例中,应用程序是网站的一部分,因此我们需要使用Web管理将其部署为应用程序以使其工作。日志和其他所有内容现在都在运行,我们有一个正在运行的示例。

我一直在使用docker容器,我也遇到了类似的问题。我正在使用服务器核心映像,因为它上面有完整的fledge powershell,但我有这样定义的dockerfile来构建映像,因为应用程序似乎无法启动。该应用程序还没有核心,但很快就会迁移到它,以使工作图像更小。从这个示例中需要注意的另一件事是,即使在我的命令中定义应用程序池,也不会创建应用程序池。有了这个,您可以使用iis远程管理工具远程连接,并检查服务器在docker中如何设置到这一点:

##Pull the base image to use
FROM mcr.microsoft.com/windows/servercore/iis
#Enable verbose output in case of errors
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
#install all needed features of IIS
RUN Install-WindowsFeature -name Web-Server -IncludeManagementTools ;\
    Install-WindowsFeature -name Web-Basic-Auth ;\
    Install-WindowsFeature -name Web-Windows-Auth ;\
    Install-WindowsFeature -name Web-Net-Ext45 ;\
    Install-WindowsFeature -name Web-ISAPI-Ext ;\
    Install-WindowsFeature -name Web-ISAPI-Filter ;\
    Install-WindowsFeature -name Web-WHC ;\
    Install-WindowsFeature NET-Framework-45-ASPNET ; \
    Install-WindowsFeature Web-Asp-Net45 ;\
    Install-WindowsFeature -Name Web-Mgmt-Service ;\
    Install-WindowsFeature -name Web-Mgmt-Tools ;\
    Install-WindowsFeature -name Web-Mgmt-Compat ;\
    Install-WindowsFeature -name Web-Scripting-Tools ;\
    Dism /online /enable-feature /featurename:IIS-ManagementService /all ;\
    ##Still inside the same run command, enable remote management for IIS on docker
    New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force ;\
    Get-Service -Name WMSVC | Start-Service ;\
    Set-Service –Name WMSVC –StartupType 'Automatic' ;\
    ##In the same run Command add the user and password for IIS remote management
        net user myuser superP@ss123 /ADD ;\
        net localgroup administrators myuser /add

    COPY . myapp
    RUN New-WebAppPool myapp
#The configStore is an application of a website, so add it as such to the service
RUN Import-Module WebAdministration; Get-Module ;\
    New-Item 'IIS:Sites\Default Web Site\myapp' -physicalPath 'c:\myapp' -ApplicationPool 'myapp' -type 'Application'

EXPOSE 51329 80

我没有回答的另一个问题是,我们是否可以在创建时为docker图像分配内存大小,而不仅仅是所有者的标准。


0
投票

一个月后,我有另一种方法来到容器的IIS ...

我将在这里发布答案,以防有人遇到类似的问题

该设置与https://blogs.msdn.microsoft.com/containerstuff/2017/02/14/manage-iis-on-a-container-with-the-iis-admin-console/有很大关系

不同之处是:

要在容器中完全安装IIS,请使用以下DockerFile:

(在文档中遗漏了一些步骤,如果没有以下Dockerfile中包含的以下行,则无法安装wmsvc和IIS管理服务)

FROM microsoft/dotnet-framework:4.6.2

RUN powershell -Command Install-WindowsFeature -name Web-Server -IncludeManagementTools

RUN powershell -Command Add-WindowsFeature web-webserver

RUN powershell -Command Install-WindowsFeature -name Web-Basic-Auth

RUN powershell -Command Install-WindowsFeature -name Web-Windows-Auth

RUN powershell -Command Install-WindowsFeature -name Web-Net-Ext45

RUN powershell -Command Install-WindowsFeature -name Web-Asp-Net45

RUN powershell -Command Install-WindowsFeature -name Web-ISAPI-Ext

RUN powershell -Command Install-WindowsFeature -name Web-ISAPI-Filter

RUN powershell -Command Install-WindowsFeature -name Web-WHC

RUN powershell -Command Install-WindowsFeature -name Web-Mgmt-Tools

RUN powershell -Command Install-WindowsFeature -name Web-Mgmt-Compat

RUN powershell -Command Install-WindowsFeature -name Web-Mgmt-Service

RUN powershell -Command Install-WindowsFeature -name Web-Scripting-Tools

RUN powershell Dism /online /enable-feature /featurename:IIS-ManagementService /all
  1. Docker run图像用-it / Docker attach容器
  2. 通过输入powershell启动容器的powershell
  3. 运行Get-service以查看IISadmin,w3svc和wmsvc是否存在。

它会显示wmsvc没有启动(奇怪的是,即使我在DockerFile中运行sc config wmsvc start=auto仍然无效)

  1. net start的服务
  2. 使用主机的IIS连接到容器的IIS(类似于上面链接给出的步骤)

它应该能够从主机连接到容器,现在您已经在容器中成功实现了Web应用程序。

PS。请注意,防火墙可能会阻止远程管理进程

© www.soinside.com 2019 - 2024. All rights reserved.