简体   繁体   中英

From a docker container how do I see another docker container?

Based on: https://github.com/osixia/docker-phpLDAPadmin

I am running OpenLDAP and phpLDAPadmin containers with:

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).

I also start another container from a JIRA image with:

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:

https://172.17.0.3/

and jira on:

http://localhost:8087

Next I try to configure a LDAP directory in JIRA pointing to the running OpenLDAP server with but get the below error:

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.

I have also tried: 172.17.0.3 on the jira side but same result.

How do I get the jira container to see the OpenLDAP container?

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:

在此处输入图片说明

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 .
(this replaces the obsolete legacy container links )

Then you can reference your LDAP using its container IP address.

Containers connected to the default bridge network can communicate with each other by IP address. Docker does not support automatic service discovery on the default bridge network.

As BMitch adds in the comments , you should reference ldap with its service name, not ldap-host :

--env PHPLDAPADMIN_LDAP_HOSTS=ldap-service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM