背景
最近在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
(完)