window10 - docker desktop 環境下,使用固定的IP作為本機 docker container 地址


背景

最近在win10上面折騰docker, 由於機器沒有分配固定的IP地址,每次重啟之后IP地址都會變化,每次調試都需要改配置,非常麻煩 :(

 

解決

查看本機hosts文件 (C:\Windows\System32\drivers\etc\hosts),發現在安裝 docker desktop后, docker已經為配置了默認的子網和gatewa,具體如下:

# Added by Docker Desktop
139.24.227.29 host.docker.internal
139.24.227.29 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

 

可以看到,139.24.227.29 的 IP 地址已經被docker 所使用,因此,我們就可以使用這個IP作為固定的IP配置,供docker continer 之間通信使用。 

本機 docker container 之外的app, 可以使用 127.0.0.1

 

(完)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM