Docker容器链接

时间:2016-09-23 11:59:34

标签: docker dns

我有一个nginx路由到两个app容器。

我有一个在其中一个容器中运行的登录应用程序 - account.myproduct.local

我的其他应用程序正在其他容器中运行 - calendar.myproduct.local

如果向calendar.practo.local发出请求,则会将Openid身份验证重定向到account.myproduct.local

问题: 我已链接容器,但由于account.myproduct.local无法从日历容器(calendar.myproduct.local)解析,因此不会发生登录。 我应该如何解决它?

2 个答案:

答案 0 :(得分:0)

您可以使用link命令为calendar.myproduct.local的/ etc / hosts添加别名。您在日历上的链接将是这样的:

--link account_container_name:account.myproduct.local

这样,calendar.myproduct.local将能够解析主机名account.myproduct.local而无需知道其IP。

答案 1 :(得分:0)

<强>解决 使用泊坞窗版本1.10及更高版本。无需链接容器,因为docker-compose构成默认网络,并且容器名称可以发现所有服务。将服务名称更改为nginx服务器名称解决了我的问题。

现在,accounts.myproduct.local和calendar.myproduct.local可从外部解析(coz of the /etc/hosts in my mac),也可在内部解析以进行通信(using the service name which is resolvable in the same network

详细信息以及正确的示例: https://github.com/alok87/dockerex

新的docker-compose文件:

version: '2'

services:
   accounts.myproduct.local:
     build: accounts

   calendar.myproduct.local:
     build: calendar

   router:
     build: router
     ports:
     - 80:80