Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

  • I want to run a docker container that'll host a micro-service
  • The micro-service has dependencies upon databases that I'm also running via docker
  • I thought I'd be able to use --net=host on Mac when running the micro-service
  • But the micro-service port is not exposed
  • I can override the db addresses (they default to localhost) on the microservice.
  • But that involves robust --env usage
  • What's the simplest / most elegant solution?

    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.

    This forces me to do step 6. above. I can't reference the db at localhost instead I'd need to reference the container-name-for-db. I'm hoping to find a solution where this is not required. That'll allow me to use the micro-service defaults (which are localhost). – Shane Gannon Sep 28, 2018 at 16:42 On docker for mac you can use host.docker.internal as host to access localhost but this is still not solving your real issue probably. Also --add-host is an option but mapping localhost to your db container name seems like a bad idea stackoverflow.com/questions/31324981/… – lvthillo Sep 28, 2018 at 21:32 Or a solution like thise (I don't know grok so don't shoot at me if it's a bad solution) fullstack.network/… – lvthillo Sep 28, 2018 at 21:35

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.