According to the docker documentation here
https://docs.docker.com/network/host/
The host networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server.
On Mac what alternatives do people use?
My scenario
What's the simplest / most elegant solution?
Docker can't run natively since it uses linux kernel features not available on a mac.
UPDATE 2022-06-28: I'm still using this setup. Works amazingly. Haven't thought about Docker Desktop until someone gilded me for this post.
Here's a quick summary with the best benefits of using Docker for Mac: Pretty smooth and simple installation process. No more VirtualBox! No problems with virtual machines, filesystems or other bugs you might have encountered with the Docker Toolbox.
You can run both HyperKit and Oracle VirtualBox on the same system. To learn more, see Docker for Mac vs. Docker Toolbox. So it seems like if you are not concerned about docker-machine create then you can use Docker CE without VirtualBox installed.
The most simple and most elegant solution is to use docker named bridge network. You can create a custom bridge network (default is bridge) like this:
docker network create my-network
Every container deployed inside this network can communicate with each other by using the container name.
$ docker run --network=my-network --name my-app ...
$ docker run --network=my-network --name my-database...
In the example above you can connect to your database from inside your application by using my-database:port
. If the container port is exposed in the Dockerfile you don't need to map it on your host and you can keep all your communication internal inside your custom docker bridge network.
In most cases the application its port is mapped (example: -p 80:80
) so localhost:80
is mapped on container:80
and you can access the app from on your localhost. If the app needs to communicate with a db you don't need to expose the port of the db and you don't have to map it on localhost as explained already above.
Just keep the communication between app and db internal in your custom bridge network.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With