啟動MS SQL容器發生Ports are not available錯誤

啟動MS SQL容器發生Ports are not available錯誤

今天要測個MS SQL的東西時,啟動MS SQL容器時發生Ports are not available錯誤。

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" -p 1433:1433 --name sql1 --hostname sql1 -d mcr.microsoft.com/mssql/server:2022-latest
c71dce344559b7e9188144b69329bdeca50e85984742d0c97ea73d3b1a40c5cf
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:1433 -> 0.0.0.0:0: listen tcp 0.0.0.0:1433: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

奇怪的是,我用 netstat 查詢,Port 1433 並沒有被佔用。

netstat -a

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:7              kkbruce:0              LISTENING
  TCP    0.0.0.0:9              kkbruce:0              LISTENING
  TCP    0.0.0.0:13             kkbruce:0              LISTENING
  TCP    0.0.0.0:17             kkbruce:0              LISTENING
  TCP    0.0.0.0:19             kkbruce:0              LISTENING
  TCP    0.0.0.0:135            kkbruce:0              LISTENING
  TCP    0.0.0.0:445            kkbruce:0              LISTENING
  TCP    0.0.0.0:1025           kkbruce:0              LISTENING
  TCP    0.0.0.0:2179           kkbruce:0              LISTENING
  TCP    0.0.0.0:5040           kkbruce:0              LISTENING
  TCP    0.0.0.0:7680           kkbruce:0              LISTENING
  TCP    0.0.0.0:49664          kkbruce:0              LISTENING
  TCP    0.0.0.0:49665          kkbruce:0              LISTENING
  TCP    0.0.0.0:49666          kkbruce:0              LISTENING
  TCP    0.0.0.0:49667          kkbruce:0              LISTENING
  TCP    0.0.0.0:49668          kkbruce:0              LISTENING
  TCP    0.0.0.0:59869          kkbruce:0              LISTENING
  TCP    127.0.0.1:7777         kkbruce:0              LISTENING
  TCP    127.0.0.1:19010        kkbruce:0              LISTENING
  TCP    127.0.0.1:29678        kkbruce:0              LISTENING
  TCP    127.0.0.1:62978        kkbruce:0              LISTENING
  TCP    172.23.208.1:139       kkbruce:0              LISTENING
  TCP    172.31.80.1:139        kkbruce:0              LISTENING
  TCP    192.168.8.148:139      kkbruce:0              LISTENING
  TCP    192.168.8.148:1026     20.90.152.133:https    ESTABLISHED

試了好幾次都這樣,利用關鍵字快速在 docker Issues #9272找到一個解法:

net stop winnat
net start winnat

winnat 重啟後就一切正常了。正在奇怪,爬到黑大的一篇文。清除重啟後利用 netsh 查詢是沒有看到 Port 1433。

netsh int ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
     50000       50059     *

* - Administered port exclusions.

這裡比較可惜,我先清 winnat 才看到黑大的文,在此 Docker Case 裡,我沒有找到真正兇手,只找到解決辦法。而我最近確在有大量的 Lab / PoC 使用 Hyper-V,但怎麼會去佔用 Port 1433 呢,這我無法解釋,我也不敢說一定是 Hyper-V 造成的,證據已經被我清的一乾二淨了。哈哈哈!

2023/12/5:抓到了!犯人就是它!

netsh int ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
      1044        1143
      1144        1243
      1244        1343
      1344        1443
      1444        1543
      1544        1643
      1644        1743
      1744        1843
      1914        2013
      2709        2808
      2809        2908
      2909        3008
      3009        3108
      3109        3208
      3209        3308
      3309        3408
      3409        3508
      3509        3608
     50000       50059     *

* - Administered port exclusions.

沒有留言:

張貼留言

感謝您的留言,如果我的文章你喜歡或對你有幫助,按個「讚」或「分享」它,我會很高興的。