When i create application pool of IIS image, container not work

OS:Windows 10 Pro

Dockerfile

FROM microsoft/iis
RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*

WORKDIR /inetpub/wwwroot
COPY content/ .

RUN powershell Remove-WebSite -Name 'Default Web Site'
RUN powershell New-WebSite -Name 'mysite' -Port 8081 -PhysicalPath 'c:\inetpub\wwwroot' -ApplicationPool 'myapp'

EXPOSE 8081

.yml file:

version: '3.7'

services:
  demo-index:
    build: ./iis-demo    
    ports:
      - 8081:8081

Error:
PS C:\Users\admin\Desktop> curl 172.23.53.214:8081

curl : Unable to connect to the remote server
At line:1 char:1

  • curl 172.23.53.214:8081
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestComman
    
    

Note:
Without creating application pool it works

Please help
I am totally upset how to do it properly

Hi,

I had the same issue and it link to the way the IIS team build the image using ServiceMonitor.exe. You cannot use another apppool than DefaultApplicationPool. I guess it is mention on the iis team github.

In my case I had to use windows server image unstead of iis image.

Here the part of my Dockerfile that install the IIS components I need :

# escape=`
FROM microsoft/windowsservercore:1709
...
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; "]
RUN Add-WindowsFeature Web-Server, Web-Http-Redirect, Web-Http-Tracing, Web-Dyn-Compression, Web-Windows-Auth, Web-Asp, NET-Framework-45-ASPNET, NET-WCF-HTTP-Activation45, Web-Asp-Net45;
RUN 	c:\Windows\System32\inetsrv\appcmd.exe set config -section:system.applicationHost/log /centralLogFileMode:"CentralW3C" /commit:apphost; `
	c:\Windows\System32\inetsrv\appcmd.exe set config -section:system.applicationHost/log /centralW3CLogFile.truncateSize:4294967295 /commit:apphost; `
	c:\Windows\System32\inetsrv\appcmd.exe set config -section:system.applicationHost/log /centralW3CLogFile.period:"MaxSize" /commit:apphost;
...
ENTRYPOINT C:\EntryPoint.ps1 -Verbose

The entry point script configure OS for the app and finish by showing logs

netsh http flush logbuffer | Out-Null

while (!(Test-Path 'C:\inetpub\logs\LogFiles\W3SVC\u_extend1.log')) 
{ Start-Sleep 10 }
Get-Content -path 'C:\inetpub\logs\LogFiles\W3SVC\u_extend1.log' -Tail 1 -Wait

I found the best solution to create application pool inside IIS
See Below Dockerfile code:

FROM microsoft/iis
RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*
RUN powershell Remove-WebSite -Name 'Default Web Site'
RUN powershell Import-Module WebAdministration;New-Item –Path IIS:\AppPools\XpNDFAsiaPool;New-Item -Path $env:systemdrive\inetpub\XpNDFAsiaClient -Type Directory;New-Item -Path $env:systemdrive\inetpub\XpServerDllFiles -Type Directory;New-WebSite -Name XpNDFAsiaSite -Port 4847 -PhysicalPath "$env:systemdrive\inetpub\XpNDFAsiaClient" -ApplicationPool XpNDFAsiaPool -Force;

WORKDIR /inetpub/XpNDFAsiaClient
COPY content/ .

EXPOSE 4847

Hi @sk5277, was able to create a image using the above script. But after running the container, how to browse the hosted site with the exposed port? Can you please guide me?

@rajeshgandhi use

docker container ls #to find the name/container id of the running container
docker inspect -f “{{ .NetworkSettings.Networks.nat.IPAddress }}” <containerId/name recievd from above step
xxx.xxx.xxx.xxx

Now, open your browser and use this ip address along with the port exposed to access the hosted IIS website