暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Mac下如何直接连接到Docker容器

原创 无心 2024-08-14
247

在mac中使用docker时,假如要使用一个rockylinux容器,在这个容器中去做一些实验,使用终端工具无法连接到这个容器,操作有诸多不便,以下方式可以方便客户端工具直接访问docker容器:

参考:https://www.cnblogs.com/matytan/p/15519539.html

亲测过程如下:

# 安装docker-connector brew install wenjunxiao/brew/docker-connector # 查看docker-connector安装位置 brew list docker-connector # 找到homebrew.docker-connector.service并查看docker-connector.conf位置 brew list docker-connector /opt/homebrew/Cellar/docker-connector/3.1/bin/docker-connector /opt/homebrew/Cellar/docker-connector/3.1/homebrew.docker-connector.service /opt/homebrew/Cellar/docker-connector/3.1/homebrew.mxcl.docker-connector.plist /opt/homebrew/Cellar/docker-connector/3.1/sbom.spdx.json cd /opt/homebrew/Cellar/docker-connector/3.1/ cat homebrew.docker-connector.service [Unit] Description=Homebrew generated unit for docker-connector [Install] WantedBy=default.target [Service] Type=simple ExecStart=sudo /opt/homebrew/opt/docker-connector/bin/docker-connector -config /opt/homebrew/etc/docker-connector.conf Restart=always WorkingDirectory=/opt/homebrew/var StandardOutput=append:/opt/homebrew/var/log/docker-connector.log StandardError=append:/opt/homebrew/var/log/docker-connector.log # 找到配置文件/opt/homebrew/etc/docker-connector.conf的位置 # 将docker网络追加到docker-connector.conf配置文件中 docker network ls --filter driver=bridge --format "{{.ID}}" | xargs docker network inspect --format "route {{range .IPAM.Config}}{{.Subnet}}{{end}}" >> /opt/homebrew/etc/docker-connector.conf # 启动docker-connector服务 sudo brew services start docker-connector # 运行能打通网络的容器 docker run -it -d --restart always --net host --cap-add NET_ADMIN --name connector wenjunxiao/mac-docker-connector # 运行一个nginx容器 docker run --name ng1 -itd nginx # 测试网络 ping 172.17.0.2 或访问nginx页面
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论