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>
相关推荐
沐浴露z1 小时前
详解 零拷贝(Zero Copy):mmap、sendfile、DMA gather、splice
java·网络·操作系统
进击的圆儿1 小时前
10个TCP可靠性与拥塞控制题目整理
网络·c++·tcp/ip
Better Bench1 小时前
【大模型RAG安全基准】安装和使用SafaRAG框架
网络·人工智能·安全·大模型·组件·rag
☆璇3 小时前
【Linux】Reactor反应堆模式
linux·运维·服务器·网络
七七七七073 小时前
【计算机网络】UDP协议深度解析:从报文结构到可靠性设计
服务器·网络·网络协议·计算机网络·算法·udp
半桔3 小时前
【IO多路转接】epoll 高性能网络编程:从底层机制到服务器实战
linux·运维·服务器·网络·php
come112343 小时前
深入解析抖音和CSDN的推荐逻辑的区别
网络
爱编程的鱼3 小时前
301 是什么意思?——HTTP 状态码详解与应用
网络·网络协议·http
尽兴-4 小时前
macOS 系统下 Chrome 浏览器安装 HTTPS 证书完整指南
chrome·macos·https·证书·ssl·pem·crt
专注于大数据技术栈4 小时前
Mac本地安装python
macos