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