I have a Mac laptop with docker-machine's running a container with nginx and several other apps on other containers. I can contact my apps through the host vm -> through nginx container -> into app container.
I would like to have applications contact another application running on my Mac (for debugging). Is this possible?
Yes, it is possible. One simple way is use --link
option
docker run -ti --link mysql:mysql <Docker_image>
As recommended by @Matt, you can also build the network with latest docker.
refer User-defined networks
Yes, you can contact services on the docker-machine VM host via TCP/IP. The default docker virtual machines have two network interfaces attached to them.
The first network adapter is attached to the NAT network for internet access. This provides a route to the main adapters address on your laptop, which is normally 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@default-docker:~$ curl http://192.168.10.33:3000/time
{"time":{"now":1454987348431,"start":1454635891001}}
There is a second Host-only adapter used for docker management. The Name of the Host-only adapter in VirtualBox will map to an interface on your host.
→ 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
→ 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.