简体   繁体   English

Mac主机上的Docker-machine的容器联系人应用程序

[英]Docker-machine's container contact application on Mac host

I have a Mac laptop with docker-machine's running a container with nginx and several other apps on other containers. 我有一台Mac笔记本电脑,带有docker-machine的服务器,运行带有nginx的容器以及其他容器上的其他几个应用程序。 I can contact my apps through the host vm -> through nginx container -> into app container. 我可以通过主机vm->通过nginx容器->进入应用容器来联系我的应用。

I would like to have applications contact another application running on my Mac (for debugging). 我想让应用程序与Mac上运行的另一个应用程序联系(进行调试)。 Is this possible? 这可能吗?

Yes, it is possible. 对的,这是可能的。 One simple way is use --link option 一种简单的方法是使用--link选项

docker run -ti --link mysql:mysql <Docker_image>

Notes: 笔记:

As recommended by @Matt, you can also build the network with latest docker. 按照@Matt的建议,您还可以使用最新的docker构建网络。

refer User-defined networks 参考用户定义的网络

Yes, you can contact services on the docker-machine VM host via TCP/IP. 是的,您可以通过TCP / IP与docker-machine VM主机上的服务联系。 The default docker virtual machines have two network interfaces attached to them. 默认docker虚拟机具有两个连接的网络接口。

Adapter 1 转接器1

The first network adapter is attached to the NAT network for internet access. 第一个网络适配器连接到NAT网络以进行Internet访问。 This provides a route to the main adapters address on your laptop, which is normally en0 这提供了通往笔记本电脑上主适配器地址的路由,该地址通常为en0

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

You can use this address from inside your docker VM or containers to access services that are running on your mac. 您可以从Docker VM或容器内部使用此地址来访问在Mac上运行的服务。

docker@default-docker:~$ curl http://192.168.10.33:3000/time
{"time":{"now":1454987348431,"start":1454635891001}}

Adapter 2 适配器2

There is a second Host-only adapter used for docker management. 还有另一个用于docker管理的仅限主机的适配器。 The Name of the Host-only adapter in VirtualBox will map to an interface on your host. VirtualBox中仅主机适配器的名称将映射到主机上的接口。

→ 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

Your mac will have a corresponding interface 您的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

You can also use this address. 您也可以使用该地址。

docker@default-docker:~$ curl http://192.168.99.1:3000/time
{"time":{"now":1454987348590,"start":1454635891001}}

The host only adapter address is useful if your network IP changes and you need to configure something static in a container, the host adapter address' will remain consistent (unless you destroy your vm, then it might change) 如果网络IP发生更改并且您需要在容器中配置静态内容,则仅主机适配器地址很有用,“主机适配器地址”将保持一致(除非您销毁了vm,否则它可能会更改)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker容器在主机中无法访问 - Docker container not accessible in host machine Nginx不会在ubuntu的docker-compose中转发到django应用程序,但都可以在Mac的docker-machine中工作 - nginx doesn't forward to django app in docker-compose in ubuntu but it all works in docker-machine in Mac 从docker调用docker的主机 - call docker's host machine from docker docker-machine实例未在端口8080上运行 - docker-machine instance not running on port 8080 如何在主机上运行Nginx的情况下在Docker容器中运行Rails应用程序? - How to run rails app in docker container with nginx running on host machine? 无法从主机网络上的其他计算机访问docker容器 - docker container is not accessible from other machines on host's network 如何从主机连接到docker容器的链接别名 - How to connect to docker container's link alias from host AWS上的多容器泊坞窗 - Nginx使用主机/ etc / hosts解析程序 - Multi-container docker on AWS - Nginx use host machine /etc/hosts resolver 我无法使LEMP与docker-machine和docker-compose一起运行 - I failed to get LEMP running with docker-machine and docker-compose docker-machine + docker-compose + ssl (让我们通过 nginx 和 certbot 加密) - docker-machine + docker-compose + ssl (lets encrypt through nginx & certbot)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM