nginx - Mac 主机上 Docker-machine 的容器联系应用

标签 nginx docker docker-machine

我有一台带有 docker-machine 的 Mac 笔记本电脑,它运行一个带有 nginx 的容器以及其他容器上的几个其他应用程序。我可以通过主机 vm 联系我的应用程序 -> 通过 nginx 容器 -> 进入应用程序容器。

我想让应用程序联系在我的 Mac 上运行的另一个应用程序(用于调试)。这可能吗?

最佳答案

是的,您可以通过 TCP/IP 联系 docker-machine VM 主机上的服务。默认的 docker 虚拟机有两个连接到它们的网络接口(interface)。

适配器 1

第一个网络适配器连接到 NAT 网络以访问 Internet。这提供了到笔记本电脑主适配器地址的路由,通常为 en0

→ ifconfig en0 | grep "inet "
    inet 192.168.10.33 netmask 0xffffff00 broadcast 192.168.10.255

您可以在 docker VM 或容器中使用此地址来访问在您的 mac 上运行的服务。
docker@default-docker:~$ curl http://192.168.10.33:3000/time
{"time":{"now":1454987348431,"start":1454635891001}}

适配器 2

还有第二个 Host-only 适配器用于 docker 管理。 VirtualBox 中仅主机适配器的名称将映射到主机上的接口(interface)。
→ VBoxManage showvminfo default | grep "NIC 2"
NIC 2:           MAC: 0800270D841E, Attachment: Host-only Interface 'vboxnet3', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none

你的mac会有对应的界面
→ ifconfig vboxnet3
vboxnet3: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    ether 0a:00:27:00:00:03 
    inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255

您也可以使用此地址。
docker@default-docker:~$ curl http://192.168.99.1:3000/time
{"time":{"now":1454987348590,"start":1454635891001}}

如果您的网络 IP 发生变化并且您需要在容器中配置静态内容,则仅主机适配器地址很有用,主机适配器地址将保持一致(除非您销毁您的 vm,否则它可能会更改)

关于nginx - Mac 主机上 Docker-machine 的容器联系应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35282496/

相关文章:

nginx - RoR 5.0.0 ActionCable wss WebSocket 握手 : Unexpected response code: 301

powershell - 使用 PowerShell 作为默认 Shell,但在批处理文件运行时将其丢弃

使用通用驱动程序 : x509: certificate signed by unknown authority when trying to add remote host to local machine 的 Docker 机器

linux - chmod 不适用于 virtualbox 共享文件夹

kubernetes - 使用 nginx ingress kubernetes 重写目标问题

php - laravel 发送文件时出现 HTTP ERROR 500

python - 如何检测 Tornado 环境变量

docker - 如何通过 localhost 连接两个 docker 容器?

docker - EC2实例重启时如何自动重启docker-compose集群

Docker 机器创建 : Error with pre-create check: "Hyper-v commands have to be run as an Administrator"