In my job I working with docker and the option -net=host working like a charm forwarding the docker container ports to the machine. This allows me to adding grunt tasks that use certain ports by example:. A taks for serving my coverage report in a port 9001. A local deployed version of my app served in the port 9000. A watch live reload the port 35729. For Unit testing runner use the 9876 port When I begin to use Docker in Mac, the first problem that i had was: The option -net=host don't work anymore.
![Docker check container network Docker check container network](/uploads/1/2/5/4/125428431/946227673.png)
I researched and I understand why this is not possible (Docker in Mac runs in a own virtual machine) and my momentary solution it's use the -p option for expose the ports, but this limit to me to add more and more task that use ports because i need run the explicit -p command for each port that i need expose. Anyone with this same problem? How to dealing with this? Your issue is most probably that you are using dockertoolbox or dhingy/dlite or anything else providing a full-fledged linux VM, which then hosts docker to run your container inside this VM. This VM has, of course, its own network stack and own IP on the host, and thats were your tools will have issues with. The exposed ports of the container are not exposed to OSX host localhost, but rather OSX Docker-VM-ip.
Docker is a technology focused on building container based architecture for improving developer's workflow. A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Boot2docker installs virtual machine to you mac. You could ssh into it with boot2docker ssh. That virtual machine is like a gateway to running containers. Each container is a virtual pc behind that gateway. If you ssh'ed to the vm, you could ping containers. To find out container's ip you should attach to it; docker exec -it bash.
To solve those issues elegantly Expose ports to OSX localhost from the container. First, use/install docker-for-mac instead of dockertoolbox or others. One workaround, mentioned in ' would be to use -P: (or -publish-all=true false) to which is a blanket operation that identifies every port with an EXPOSE line in the image’s Dockerfile or -expose commandline flag and maps it to a host port somewhere within an ephemeral port range.
The command then needs to be used to inspect created mapping. So if your app can use docker port to retrieve the mapped port, you can add as many containers as you want and get the mapped ports that way (without needed an 'explicit -p command for each port').