Can (or should) 2 docker containers interact with each other via localhost?

后端 未结 3 1899
礼貌的吻别
礼貌的吻别 2021-02-20 06:28

We\'re dockerizing our micro services app, and I ran into some discovery issues.

The app is configured as follows:

When the a service is started in \'non-local\'

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 06:53

    On production, never use docker or docker compose alone. Use an orchestrator (rancher, docker swarm, k8s, ...) and deploy your stack there. Orchestrator will take care of the networking issue. Your container can link each other, so you can access them directly by a name (don't care too much about the ip).

    On local host, use docker compose to startup your containers and use link. do not use a local port but the name of the link. (if your container A need to access container B on port 1234, then do a link B linked to A with name BBBB and use tcp://BBBB:1234 to access the container from A )

    If you really want to bind port to your localhost and use this, access port by your host IP, not localhost.

提交回复
热议问题