Cannot access an IIS container from browser - Dock

2019-08-19 23:48发布

问题:

Windows Version: Windows Server 2016

Docker for Windows Version: 18.09.0

I try to follow the steps in https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-images

I have a Docker file on c:\Build:

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

Please note that I have tried using FROM microsoft/iis:10.0.14393.206 as well

So, I ran using powershell with admin privilege:

docker build -t imagename c:\Build

Then I ran:

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

All of the above steps are fine, but I cannot access the website,

I tried every combination like: the ip address from ipconfig:8000 or 80; the ip address from inspect :8000 / 80. Please note that I had also set up Firewall to allow port 8000 as well

But it all failed.

Then, I went to the Internet and found that I can actucally call the bash. therefore, I ran exec, however, there was something strange happened:

I am not sure whether it means the container is not worknig? But the inspect and container ls show it should be working.

fyi network:

inspect container:

I really cannot find any solution from the Internet

Any advice would be helpful, thanks

回答1:

UPDATE: I got it to work with the following configuration below, and with remote IIS access. Make sure that firewall is not blocking docker to your local ip's. Also, the app in our case is part of a website, so we need to use Webadministration to deploy it as an application to make it work. Logs and everything else is working now and we have a running sample.

I been playing as well with the docker container and I been having similar issues deploying. I am using a server core image instead as it has full fledge powershell on it, but I have my dockerfile defined like this to build the image at the moment doing tests because the application seems to not start. the app is not on core yet but will migrate to it soon to make the working image smaller. Another thing to note from this sample, the application pool is not getting created even tho its being defined on my commands. With this you can connect remotely with the iis remote management tool and check how is the server setup up to this point inside the 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

The other question I have no answer is if we can actually assign a memory size to the docker images on creation and not just the standard by the owner.



回答2:

After a month, I have another way to get to the container's IIS...

I am going to post the answer here, in case someone encounters similar issues

The setup greatly relates to https://blogs.msdn.microsoft.com/containerstuff/2017/02/14/manage-iis-on-a-container-with-the-iis-admin-console/

The difference is:

To fully install IIS in a container, use the following DockerFile:

(There are some steps missed in the document, you cannot have wmsvc and IIS admin services installed without the following lines included in the Dockerfile below)

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 the image with -it / Docker attach the container

  2. start container's powershell by typing powershell

  3. running Get-service to see if IISadmin, w3svc and wmsvc are there.

It will show that wmsvc is not started (strangely, even I run sc config wmsvc start=auto in DockerFile still does not work)

  1. net start the service

  2. use host's IIS to connect to the container's IIS (similar to the step given by the link above)

It should be able to connect to the container from host and now you have successfully implemented a web application in a container.

PS. Note that firewall may block the remote management process