简体   繁体   English

如何从Docker容器中看到另一个Docker容器?

[英]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.

相关问题 如何从另一个 docker 容器中运行的应用程序启动 Docker-Compose 中的 docker 容器 - How do I start a docker container in Docker-Compose from an app running in another docker container 如何从另一个 docker 容器中调用 ansible 剧本坐在 docker 容器上 - How do I call a ansible playbook sitting on a docker container from another docker container 如何在网络内从另一个Docker容器引用一个Docker容器? - How do I refer to a docker container from another docker container, inside a network? 如何从一个docker容器ssh到另一个docker容器? - How do I ssh from one docker container to another docker container? 如何从另一个Docker容器中运行命令? - How do I run a command from one Docker container in another? 如何将 docker 容器端口暴露给另一个容器 - How do I expose a docker container port to another container 如何连接到docker容器的localhost(从容器内部) - How do I connect to the localhost of a docker container (from inside the container) 如何从另一个容器访问在Docker容器中运行的Mopidy - How do I access Mopidy running in Docker container from another container 从 Docker 容器内部,如何连接到同一容器内侦听的另一个进程? - From inside of a Docker container, how do I connect to another process listening inside the same container? 如何在 Docker Compose 中将目录从一个容器复制到另一个容器? - How do I copy a directory from one container to another container in Docker Compose?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM