Docker容器网络配置故障:JIRA、OpenLDAP与phpLDAPadmin连通问题
Let's walk through what's going wrong and how to get your phpLDAPadmin talking to OpenLDAP again with the custom network setup:
What's Causing the Problem
When you used --link ldap-service:ldap-host earlier, Docker created an internal hostname alias ldap-host that pointed to your OpenLDAP container inside the phpLDAPadmin container. But once you switched to the custom sample-network and removed the --link flag, that alias disappeared. Your phpLDAPadmin is still trying to connect to ldap-host, which it can't resolve in the new network—even though custom networks support DNS resolution for container names directly.
Step-by-Step Solution
1. Clean Up the Old phpLDAPadmin Container
First, shut down and remove the misconfigured phpLDAPadmin container:
docker stop phpldapadmin-service docker rm phpldapadmin-service
2. Re-launch phpLDAPadmin with Correct Settings
Start a new phpLDAPadmin container, add it to your custom network, and update the environment variable to use the actual OpenLDAP container name (which the custom network can resolve via DNS):
docker run --name phpldapadmin-service \ --hostname phpldapadmin-service \ --network sample-network \ --env PHPLDAPADMIN_LDAP_HOSTS=ldap-service \ --detach osixia/phpldapadmin:0.7.1
3. Verify the Connection
Once the container is running, access phpLDAPadmin via your browser (using https://172.17.0.3/ as before) and test the LDAP connection. It should now successfully resolve ldap-service through the custom network's built-in DNS.
Why This Works
Custom Docker bridge networks come with native DNS resolution that lets containers communicate using each other's container names directly. By setting PHPLDAPADMIN_LDAP_HOSTS=ldap-service, you're telling phpLDAPadmin to target the OpenLDAP container by its actual name—no need for the deprecated --link flag anymore.
Quick Check: Ensure All Containers Are in the Same Network
Double-confirm that your OpenLDAP and JIRA containers are also part of sample-network (you mentioned you added them, but it's good to verify):
docker network inspect sample-network | grep -E "Name|ldap-service|phpldapadmin-service|mycontainer"
All three container names should appear under the "Containers" section of the output.
内容的提问来源于stack exchange,提问作者u123

