[英]From a docker container how do I see another docker container?
Based on: https://github.com/osixia/docker-phpLDAPadmin 基于: https : //github.com/osixia/docker-phpLDAPadmin
I am running OpenLDAP and phpLDAPadmin containers with: 我使用以下命令运行OpenLDAP和phpLDAPadmin容器:
docker run --name ldap-service --hostname ldap-service --detach -p 389:389 -p 636:636 --detach osixia/openldap:1.1.8
docker run --name phpldapadmin-service --hostname phpldapadmin-service --link ldap-service:ldap-host --env PHPLDAPADMIN_LDAP_HOSTS=ldap-host --detach osixia/phpldapadmin:0.7.1
(based on suggestions below I have also tried -p 689:689
and adjust accordingly in jira but get the same errors). (基于以下建议,我也尝试了-p 689:689
并在jira中进行了相应调整,但得到相同的错误)。
I also start another container from a JIRA image with: 我还从JIRA映像中启动了另一个容器,其内容如下:
docker run -p 0.0.0.0:8087:8087 -d --name mycontainer jiraimage tail -f/dev/null
In my browser on my host machine I can access the phpldapadmin web interface on: 在主机上的浏览器中,我可以在以下位置访问phpldapadmin Web界面:
https://172.17.0.3/ https://172.17.0.3/
and jira on: 和吉拉:
http://localhost:8087 HTTP://本地主机:8087
Next I try to configure a LDAP directory in JIRA pointing to the running OpenLDAP server with but get the below error: 接下来,我尝试在JIRA中配置一个指向正在运行的OpenLDAP服务器的LDAP目录,但出现以下错误:
Connection test failed. Response from the server:
ldap-service:636; nested exception is javax.naming.CommunicationException: ldap-service:636 [Root exception is java.net.UnknownHostException: ldap-service]
So it seems the JIRA container cannot see the hostname of the OpenLDAP container. 因此,JIRA容器似乎看不到OpenLDAP容器的主机名。
I have also tried: 172.17.0.3
on the jira side but same result. 我也尝试过:在jira端上为172.17.0.3
,但结果相同。
How do I get the jira container to see the OpenLDAP container? 如何获取jira容器以查看OpenLDAP容器?
More info: 更多信息:
# docker version
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:45 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:41:24 2017
OS/Arch: linux/amd64
Experimental: false
And: 和:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
de167e404cc3 jiraimage tail -f /dev/null" 6 seconds ago Up 4 seconds 0.0.0.0:8087->8087/tcp mycontainer
3a4a771037ac osixia/phpldapadmin:0.7.1 "/container/tool/run" 6 seconds ago Up 5 seconds 80/tcp, 443/tcp phpldapadmin-service
aa2d78fdcd99 osixia/openldap:1.1.8-001 "/container/tool/run" 7 seconds ago Up 5 seconds 0.0.0.0:389->389/tcp, 0.0.0.0:636->636/tcp, 636/tcp ldap-service
Based on the below answer regarding creating a user defined network I now have a connection: 基于以下有关创建用户定义网络的答案,我现在有了一个连接:
I first create a user defined network with: 我首先使用以下方法创建用户定义的网络:
docker network create --driver bridge sample-network
and start my containers with: 并以以下内容启动我的容器:
docker run --network=sample-network --name ldap-service --hostname ldap-service --detach -p 389:389 -p 636:636 --detach osixia/openldap:1.1.8
docker run --network=sample-network --name phpldapadmin-service --hostname phpldapadmin-service --env PHPLDAPADMIN_LDAP_HOSTS=ldap-host --detach osixia/phpldapadmin:0.7.1
docker run --network=sample-network -p 0.0.0.0:8087:8087 -d --name mycontainer jiraimage tail -f/dev/null
I had to remove: --link ldap-service:ldap-host
from the LDAP container so phpadmin can no longer connect to openldap: 我必须从LDAP容器中删除--link ldap-service:ldap-host
,因此phpadmin无法再连接到openldap:
What do I need to change to re-enable that? 我需要更改以重新启用该功能?
Simply define first a network and add your two containers to that network. 只需首先定义一个网络,然后将两个容器添加到该网络。
See docker container networking . 请参阅Docker容器网络 。
(this replaces the obsolete legacy container links ) (这将替换过时的旧容器链接 )
Then you can reference your LDAP using its container IP address. 然后,您可以使用其容器IP地址引用LDAP。
Containers connected to the default bridge network can communicate with each other by IP address. 连接到默认网桥网络的容器可以通过IP地址相互通信。 Docker does not support automatic service discovery on the default bridge network. Docker不支持默认网桥网络上的自动服务发现。
As BMitch adds in the comments , you should reference ldap with its service name, not ldap-host
: 正如BMitch 在注释中添加的那样 ,您应该使用其服务名称而不是ldap-host
引用ldap:
--env PHPLDAPADMIN_LDAP_HOSTS=ldap-service
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.