我一直在为这个问题揪头发。 在某个地方,似乎有一些旧的端口映射被留在了我的windows server 2016 docker服务器中,而且无法删除它们。 这是我试图运行的命令和错误。
PS C:\Users\...\Desktop> Get-NetNatStaticMapping | Remove-NetNatStaticMapping
Confirm
Are you sure you want to perform this action?
Performing operation Delete on Target H54d664a6-523c-4452-b137-d66701623488;20;0 PolicyStore Local
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): a
Remove-NetNatStaticMapping : The requested operation is not supported.
At line:1 char:27
+ Get-NetNatStaticMapping | Remove-NetNatStaticMapping
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (MSFT_NetNatStat...b4d01327e;6...):root/StandardCi...atStaticMapping)
[Remove-NetNatStaticMapping], CimException
+ FullyQualifiedErrorId : Windows System Error 50,Remove-NetNatStaticMapping
Remove-NetNatStaticMapping : The requested operation is not supported.
At line:1 char:27
+ Get-NetNatStaticMapping | Remove-NetNatStaticMapping
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (MSFT_NetNatStat...701623488;2...):root/StandardCi...atStaticMapping)
[Remove-NetNatStaticMapping], CimException
+ FullyQualifiedErrorId : Windows System Error 50,Remove-NetNatStaticMapping
下面的命令显示了两个端口映射... ...
PS C:\Users\...\Desktop> Get-NetNatStaticMapping
StaticMappingID : 20
NatName : H54d664a6-523c-4452-b137-d66701623488
Protocol : TCP
RemoteExternalIPAddressPrefix : 0.0.0.0/0
ExternalIPAddress : 0.0.0.0
ExternalPort : 443
InternalIPAddress : 172.20.95.205
InternalPort : 443
InternalRoutingDomainId : {00000000-0000-0000-0000-000000000000}
Active : False
StaticMappingID : 6
NatName : H68dfe202-0efd-480b-b78a-53ab4d01327e
Protocol : TCP
RemoteExternalIPAddressPrefix : 0.0.0.0/0
ExternalIPAddress : 0.0.0.0
ExternalPort : 443
InternalIPAddress : 172.31.142.210
InternalPort : 443
InternalRoutingDomainId : {00000000-0000-0000-0000-000000000000}
Active : False
我在windows server 2016上自动卸载和重装docker,并尝试了所有常用的技巧。
以下是我在airgapped服务器上卸载docker的命令。
docker rm -f $(docker ps --all --quiet)
docker system prune --all --volumes -f
Stop-Service docker -Verbose
Stop-Service hns -Verbose
Get-ContainerNetwork | Remove-ContainerNetwork
Get-NetNat | Remove-NetNat -Confirm:$false
Get-VMSwitch -name nat | Remove-VMSwitch -Confirm:$false
Remove-Item -Path "C:\ProgramData\Docker" -Recurse -Force
Remove-WindowsFeature -Name Containers -Verbose
Remove-WindowsFeature -Name Hyper-V -Verbose
Remove-Item C:\ProgramData\Microsoft\Windows\HNS\hns.data -Force
即使如此,我还是无法删除端口映射,后来当我试图运行另一个docker镜像,端口443转发到容器时,我得到了错误信息。
failed to create endpoint
container_name on network nat: HNS failed with error : The object already exists.
我开始觉得我唯一的选择就是将服务器恢复到本周早些时候的时间点上。
任何帮助都是非常感激的!
为了过去这个问题...删除以下注册表键。
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nsi\{eb004a20-9b1a-11d4-9123-0050047759bc}
删除该键后,我会得到空的结果 从命令。
Get-NetNat
Get-NetNatStaticMapping
参考答案来自于这里的一篇博客文章中的讨论
https:/www.thomasmaurer.ch201605set-up-a-hyper-v-virtual-switch-using-a-nat-network
在这个评论中。
我能够解决 "无效操作"-错误。事实上,我与我的办公室共享的Mircosoft顾问,能够追踪到这一点;-) 为了删除NetNat,我不得不删除了以下注册表键,这是我用powerhell命令无法删除的。
HKLMSystem/CurrentControlSet/Control/NSI{eb004a20-......7759bc}/6......。
在两台不同的机器上,密钥是一样的,所以这个可能一直是同一个GUID。 删除后,NetNat不见了,我终于可以创建一个新的。这样一来,就能像预期的那样工作了。
问好。
塞巴斯蒂安