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

 

(完)

posted @ 2020-07-16 15:39  TonyZhang24  阅读(5373)  评论(0编辑  收藏  举报