How to communicate between Docker containers via “hostname”

后端 未结 5 1212
离开以前
离开以前 2020-11-27 10:02

I plan to split my monolthic server up into many small docker containers but haven\'t found a good solution for \"inter-container communication\" yet. This is my target scen

5条回答
  •  再見小時候
    2020-11-27 10:21

    EDIT : It is not bleeding edge anymore : http://blog.docker.com/2016/02/docker-1-10/

    Original Answer
    I battled with it the whole night. If you're not afraid of bleeding edge, the latest version of Docker engine and Docker compose both implement libnetwork.

    With the right config file (that need to be put in version 2), you will create services that will all see each other. And, bonus, you can scale them with docker-compose as well (you can scale any service you want that doesn't bind port on the host)

    Here is an example file

    version: "2"
    services:
      router:
        build: services/router/
        ports:
          - "8080:8080"
      auth:
        build: services/auth/
      todo:
        build: services/todo/
      data:
        build: services/data/
    

    And the reference for this new version of compose file: https://github.com/docker/compose/blob/1.6.0-rc1/docs/networking.md

提交回复
热议问题