NetFirewallRule module not working in Docker Windows Server 2022

System Info:

I’m trying to set up SSH connection inside the container and one of the steps is to configured the firewall rule, but I keep getting the error (see below). Any help/suggestion is much appreciated. Guide that I’m trying to follow from - Get started with OpenSSH Server for Windows | Microsoft Learn

Steps to reproduce the behavior

  1. From Window Docker container (win server 2022 in my case) run command below using powershell to configure the firewall rule:
 if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
    Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
    Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}

Error:

PS C:\Users\ContainerAdministrator\.ssh> New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
New-NetFirewallRule : There are no more endpoints available from the endpoint mapper.
At line:1 char:1
+ New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_NetFirewallRule:root/standardcimv2/MSFT_NetFirewallRule) [New-Net
   FirewallRule], CimException
    + FullyQualifiedErrorId : Windows System Error 1753,New-NetFirewallRule

I don’t think there is a fiirewall in a Windows container. There isn’t in a Linux container either. Containers are for running specific processes in an isolated way. If you want to configure afirewall, you would need to do it on the host. The other thing I would not use in a container is SSH server. I have done it in Linux containers for testing, but it is usually not needed.