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>
相关推荐
Allen正心正念202529 分钟前
网络编程与通讯协议综合解析
网络
bing_feilong40 分钟前
ubuntu中的WIFI与自身热点切换
网络
bloglin999991 小时前
启动容器报错ls: cannot access ‘/docker-entrypoint-initdb.d/‘: Operation not permitted
docker·容器·eureka
CodeByV1 小时前
【网络】UDP 协议深度解析:从五元组标识到缓冲区
网络·网络协议·udp
虹科网络安全2 小时前
艾体宝洞察 | 利用“隐形字符”的钓鱼邮件:传统防御为何失效,AI安全意识培训如何补上最后一道防线
运维·网络·安全
石像鬼₧魂石2 小时前
Kali Linux 网络端口深度扫描
linux·运维·网络
yBmZlQzJ3 小时前
免费内网穿透-端口转发配置介绍
运维·经验分享·docker·容器·1024程序员节
JH30733 小时前
docker 新手入门:10分钟搞定基础使用
运维·docker·容器
适应规律3 小时前
UNeXt-Stripe网络架构解释
网络
天河归来4 小时前
在本地windows电脑使用Docker搭建xinference环境
docker·语言模型·容器