Search code examples
windowsdockeriislocalhost

What do I need to do to make a Docker-hosted local website available through localhost?


I've been hosting this website on my localhost using Docker for 2 years now. I had the bright idea to install IIS for another project, which took over the localhost.

I've turned off the WAS and W3SVC services and restarted my computer ; the IIS server is off but I still can't access Docker-hosted stuff through localhost like before. What more do I need to change ?

Thanks.


Solution

  • IIS and Docker can co-exist on localhost, but they cant use the same port(/s) at the same time. How you handle this depends on what you have configured to run in Docker and IIS.

    I've turned off the WAS and W3SVC...

    How did you turn off WAS and W3SVC? If you stopped the service, then rebooted the system, the service probably restarted after reboot. To disable a service from starting after reboot you need to set the StartupType of the service to Disabled.

    You can see if any process is currently listening on port 80 with: netstat -b -a -n -o | Select-String ':80' from Powershell(as administrator). (netstat -b -a -n -o alone is a built in command that shows all listening ports). This is the output to expect if something is listening on port 80:

      TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4
      TCP    [::]:80                [::]:0                 LISTENING       4
    

    If you Stop-Service W3SVC -Force to stop IIS (ignore WAS for a moment) and run the netstat command above again you will get no output, as it was the W3SVC service that had port 80 open (so right now your docker would work, as IIS service is not running / listening on port 80).


    To properly disable a service like IIS...

    You can check the StartupType and Status of the WAS & W3SVC services like this:

    Get-Service WAS,W3SVC | Select-Object -Property Name,StartType,Status
    

    Which after a default IIS install shows:

    Name  StartType  Status
    ----  ---------  ------
    W3SVC Automatic Running
    WAS      Manual Running
    

    To Stop and prevent automatic restart you could use the commands:

    Stop-Service W3SVC -Force
    Stop-Service WAS -Force
    Set-Service W3SVC -StartupType Disabled
    Set-Service WAS -StartupType Disabled
    

    If StartupType and Status are Disabled/Stopped respectively, IIS will NOT try and listen on port 80 even after a reboot.

    Get-Service WAS,W3SVC | Select-Object -Property Name,StartType,Status
    
    Name  StartType  Status
    ----  ---------  ------
    W3SVC  Disabled Stopped
    WAS    Disabled Stopped
    

    NOTE: you can use the Services control panel to manage the above via GUI if you prefer - you can start/stop from the right click menu on the service, and use properties dialog to access the startup type option.

    NOTE: if you want to reactivate IIS, just undo the steps in the reverse order:

    Set-Service WAS -StartupType Manual
    Set-Service W3SVC -StartupType Manual
    Start-Service W3SVC
    
    • Assuming nothing is currently using port 80, IIS will start
    • You dont need to start WAS manually, so long as its startuptype is not Disabled, W3SVC will start WAS for you.
    • StartupType can be Disabled, Manual or Automatic. Leaving WAS/W3SVC as manual may suit you, as you can Start-Service W3SVC / Stop-Service W3SVC as required. But if there is something installed in IIS that forces IIS to autostart, you should leave the services disabled to avoid issues.