Docker Community Forums

Share and learn in the Docker community.

Connection refused to connect when I added SSL Certificate on WindowsServerCore-LTSE2019

I'm trying to install an SSL certificate on windows container, but I'm getting a connection refused error.

I have the following Dockerfile, not sure what I’m doing wrong.

# escape=`

FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019

# Install IIS, ServiceMonitor.exe
RUN powershell -Command `
Add-WindowsFeature Web-Server; `
Add-WindowsFeature NET-Framework-45-ASPNET; `
Add-WindowsFeature Web-Asp-Net45; `
Add-WindowsFeature NET-WCF-TCP-Activation45; `
Add-WindowsFeature NET-WCF-HTTP-Activation45; `
Remove-WebSite -Name 'Default Web Site'; `
$downloads = `
@( `
    @{ `
        uri = 'https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.10/ServiceMonitor.exe'; `
        outFile = 'C:\ServiceMonitor.exe' `
    } `
); `
$downloads.ForEach({ Invoke-WebRequest -UseBasicParsing -Uri $psitem.uri -OutFile $psitem.outFile })

RUN mkdir C:\certs

COPY certs/ /certs

RUN powershell.exe -Command `
New-Item C:\MyApp -type directory

WORKDIR /MyApp

# COPY  all file to /inetpub/wwwroot on container
COPY MyApp/ /MyApp

RUN powershell.exe -Command `
New-Website -Name 'MyApp' -IPAddress '*' -Port 443 -PhysicalPath C:\MyApp -ApplicationPool '.NET v4.7' -Ssl -SslFlags 0;

RUN powershell.exe -Command `
  Import-Module IISAdministration; `
  Import-Module WebAdministration; `
  $pwd = ConvertTo-SecureString -String 'something2019' -Force -AsPlainText; `
  $cert = Import-PfxCertificate -Exportable -FilePath 'C:\certs\certificate.pfx' -CertStoreLocation cert:\localMachine\My -Password $pwd; `
  new-item -Path IIS:\SslBindings\0.0.0.0!443 -value $cert;


# Change the startup type of the IIS service from Automatic to Manual
RUN sc config w3svc start=demand

EXPOSE 80 ` 443

# Start "C:\ServiceMonitor.exe w3svc"
ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]