Docker Community Forums

Share and learn in the Docker community.

How to manage site in iis container using iis manager on the host windows server 2016

azure
docker

(Vishnugillela) #1

I deployed a iis container in my windows server 2016. When I try to connect to the container using iis manager on the container host, I am not able to connect to it. Kindly give me steps to connect to iis using iis manager to mange the site in container.


(Jesk) #2

Hi vishnugillela,
I had the same question of yours and I did this to solve…

First, get into container with Powershell, then use it to install IIS and IIS Management Tools:

Install-WindowsFeature -name Web-Server -IncludeManagementTools

After that, you install IIS Management Service using DISM:

Dism /online /enable-feature /featurename:IIS-ManagementService /all

And then you can enable remote access:
New-ItemProperty -Path HKLM:\software\microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force

Stop and start services:

net stop Iisadmin && net stop W3svc && net stop wmsvc
net start Iisadmin && net start W3svc && net start wmsvc

To connect you need to get the container IP:

docker inspect --format ‘{{ .NetworkSettings.IPAddress }}’ your_container_id

So you can connect using IIS Manager console from your host using the IP you got :slight_smile:

It worked for me, hope it help you! :wink:


(Janjulienn) #3

Might be a bit late, but encountered the same issue, and for reference as well. I was able to solve it by putting these lines inside my Dockerfile (of course base image should be windows container with IIS)

RUN powershell Install-WindowsFeature -Name Web-Mgmt-Service
RUN powershell New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force
RUN powershell Get-Service -Name WMSVC | Start-Service
RUN powershell net user <username> <password> /ADD
RUN powershell net localgroup administrators <username> /add

Alternatively, run those commands inside the container using powershell.

Then with my IIS, add connection in the connection pane, enter the container’s IP address, and use the you provided in the Dockerfile above.

You should be able to remote the container’s IIS using your machine’s IIS manager.

Hope this helps as well.


(Sergioo7) #4

Hello @janjulienn,
I get this error when I run that command inside my Dockerfile. Please help.

‘Start-Service’ is not recognized as an internal or external command,
operable program or batch file.
ERROR: Service ‘iis’ failed to build: The command ‘cmd /S /C powershell Get-Service -Name WMSVC | Start-Service’ returned a non-zero code: 255


(Artisticcheese) #5

What is your base image?


(Sergioo7) #6

FROM microsoft/windowsservercore


(Artisticcheese) #7

What your dockerfile contains? I don’t see any Start-Service entries above.


(Sergioo7) #8

escape=`

FROM microsoft/windowsservercore

RUN powershell -Command Add-WindowsFeature Web-Server;
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `
Invoke-WebRequest -UseBasicParsing -Uri “https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.3/ServiceMonitor.exe” -OutFile “C:\ServiceMonitor.exe”

RUN powershell Install-WindowsFeature -Name Web-Mgmt-Service
RUN powershell New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force
RUN powershell Get-Service -Name WMSVC | Start-Service
RUN powershell net user admin Rlink123 /ADD
RUN powershell net localgroup administrators admin /add

EXPOSE 80

ENTRYPOINT [“C:\ServiceMonitor.exe”, “w3svc”]


(Artisticcheese) #9

Put this directly under escape and remove all references to powershell.

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]


(Artisticcheese) #10

Here is step by step with everything written in powershell


(Sergioo7) #11

Thank you for your reply, the step above is throwing another error FYI.

-Command : The term ‘-Command’ is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:76

  • … = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’; -Command Add-Win …
  •                                                      ~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (-Command:String) [], ParentCont
      ainsErrorRecordException
    • FullyQualifiedErrorId : CommandNotFoundException

(Artisticcheese) #12

What is your dockerfile looks like


(Artisticcheese) #13

Never mind, remove everything relevant to powershell including command. So it will be just RUN Add-WindowsFeature


(Sergioo7) #14

escape=`

FROM microsoft/windowsservercore

SHELL [“powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]

RUN -Command Add-WindowsFeature Web-Server; `
Invoke-WebRequest -UseBasicParsing -Uri “https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.3/ServiceMonitor.exe” -OutFile “C:\ServiceMonitor.exe”

RUN Install-WindowsFeature -Name Web-Mgmt-Service
RUN New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force
RUN Get-Service -Name WMSVC | Start-Service
RUN net user admin Rlink123 /ADD
RUN net localgroup administrators admin /add

EXPOSE 80

ENTRYPOINT [“C:\ServiceMonitor.exe”, “w3svc”]


(Sergioo7) #15

Ok I will try that THANKS!!!


(Artisticcheese) #16

Remove -Command in RUN statement and replace net user etc with equivalent POwershell commands


(Sergioo7) #17

Apparently Powershell was able to understand the net user and net localgroup :smiley: Thank you @artisticcheese. It worked


(Artisticcheese) #18

Yes, it would but it’s classy to stop using cmd and use powershell for everything


(Shreedhar) #19

Great. This worked for me.