mac docker 宿主机和容器间网络打通

动因

是这样,笔者最近满怀欣喜入手Docker,看着各种文章命令都是不断点头称道:"嗯嗯,不错不错",在接下来终于准备大干一场的时候碰壁了,主要情况是说在Mac中跑了第一把的时候发现碰到,虚拟机和宿主机居然是不通的,当然也找了一下资料说linux才是天然支持docker滴,底层都有cgroup,clx吧啦吧啦,mac,windows这种其实是底层干了波虚拟机,然后要转发啥的。从我过去多次学习大数据组件入门到放弃的情况来说,网络这种事情要提前解决,不能卡着,否则后面很多破事情。找了一堆资料,自己亲测OK,而且不是很繁琐的方式,我记录下来。

办法

使用 docker-connector, 上链接

原理官网其实也说明了

动作

先是安装

bash 复制代码
brew install wenjunxiao/brew/docker-connector
bash 复制代码
docker network ls --filter driver=bridge --format "{{.ID}}" | xargs docker network inspect --format "route {{range .IPAM.Config}}{{.Subnet}}{{end}}" >> /usr/local/etc/docker-connector.conf
bash 复制代码
sudo brew services start docker-connector

然后是内部容器启动

bash 复制代码
docker run -it -d --restart always --net host --cap-add NET_ADMIN --name connector wenjunxiao/mac-docker-connector

接下来是试一把:

bash 复制代码
curl http://172.17.0.2
bash 复制代码
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
相关推荐
小堃学编程3 小时前
计算机网络(十) —— IP协议详解,理解运营商和全球网络
网络·tcp/ip·计算机网络
IPFoxy6666 小时前
探索路由器静态IP的获取方式
网络·智能路由器
雪域迷影6 小时前
PostgreSQL Docker Error – 5432: 地址已被占用
数据库·docker·postgresql
menge23336 小时前
VLAN:虚拟局域网
网络·智能路由器
ZachOn1y6 小时前
计算机网络:计算机网络概述 —— 初识计算机网络
网络·计算机网络·知识点汇总·考研必备
三金121387 小时前
SpringIoC容器的初识
网络·网络协议·rpc
莹雨潇潇7 小时前
Docker 快速入门(Ubuntu版)
java·前端·docker·容器
狼头长啸李树身8 小时前
眼儿媚·秋雨绵绵窗暗暗
大数据·网络·服务发现·媒体
SizeTheMoment9 小时前
初识HTTP协议
网络·网络协议·http
哲伦贼稳妥9 小时前
一天认识一个硬件之机房地板
运维·网络·经验分享·其他