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>
相关推荐
淼澄研学6 小时前
Proliferate开源框架技术解析与Docker部署实操
docker·容器·开源
梦想的旅途26 小时前
企业微信Webhook:自动回复为什么会连发
网络·安全·企业微信
浪兎兎7 小时前
Docker 容器技术笔记
笔记·docker·容器
SLD_Allen8 小时前
字节跳动飞连(Feilian)AI智能体零信任安全治理深度技术研究报告
网络·人工智能·安全·智能体安全
Zhu7588 小时前
在Docker环境离线部署最新版Harbor
运维·docker·容器
钱栈up11 小时前
Mac 开发机一键发版不用切环境:我这样改造了团队的后端部署脚本Maven编译卡住20分钟?我靠两步定位到2处隐蔽编译错误
开发语言·python·macos
Xxtaoaooo11 小时前
600 元 HP 小主机装 macOS:从启动盘、BIOS 到核显加速完整教程
macos·黑苹果·cpolar·mac mini·实战教程
Raas10012 小时前
企业AI网关哪个好?MAI Gateway(魔芋企业级AI网关)入选2026年企业AI网关推荐清单
网络·人工智能·gateway·企业·ai网关·mai gateway
芯盾时代12 小时前
《金融业网络安全管理办法(征求意见稿)》全条款深度拆解(一)
网络·安全·web安全
深蓝海拓12 小时前
基于QtPy (PySide6) 的PLC-HMI工程实战记录(五)为当前动作画面的信号连接变量
网络·笔记·python·学习·pyqt