Los contenedores de Docker Containers en Windows a veces no pueden usar puertos durante la puesta en marcha
Hace poco he empezado a utilizar más Docker Desktop en mi equipo con Windows 11, sobre todo junto con la extensión Remote - Containers de VS Code y el repositorio iris-python-template de @Guillaume Rongier
A veces el contenedor se inicia sin problemas, pero otras veces falla y reporta que no puede usar un puerto.
Al final, localicé el problema. Aparentemente, el servicio Windows NAT Driver utiliza un OS facility para reservar un gran rango de puertos.
Esto es lo que un admin-level command shell mostró cuando el contenedor no se inició:
PS C:\WINDOWS\system32> netsh int ipv4 show exclude proto=tcp
Protocol tcp Port Exclusion Ranges
Start Port End Port
---------- --------
80 80
443 443
5357 5357
49685 49784
49785 49884
49885 49984
50000 50059 *
50160 50259
50260 50359
50360 50459
50460 50559
50560 50659
52182 52281
52579 52678
52679 52778
52779 52878
52879 52978
52979 53078
53170 53269
53270 53369
53370 53469
53470 53569
53582 53681
53682 53781
* - Administered port exclusions.
PS C:\WINDOWS\system32>Ten en cuenta cómo estas reservas incluyen algunas que el docker-compose.yml o iris-python-template especifican:
ports:
- 52775:52773La solución fue reiniciar el servicio winnat:
PS C:\WINDOWS\system32> net stop winnat
The Windows NAT Driver service was stopped successfully.
PS C:\WINDOWS\system32> netsh int ipv4 show exclude proto=tcp
Protocol tcp Port Exclusion Ranges
Start Port End Port
---------- --------
80 80
443 443
5357 5357
50000 50059 *
* - Administered port exclusions.
PS C:\WINDOWS\system32> net start winnat
The Windows NAT Driver service was started successfully.
PS C:\WINDOWS\system32> netsh int ipv4 show exclude proto=tcp
Protocol tcp Port Exclusion Ranges
Start Port End Port
---------- --------
80 80
443 443
5357 5357
50000 50059 *
* - Administered port exclusions.
PS C:\WINDOWS\system32>Fue interesante ver que el servicio no reservó inmediatamente los rangos de puertos de nuevo. No he investigado más, pero he publicado este artículo por si alguien más se encontraba con este problema.