osixia/openldap Docker 映像无法连接到我的容器

问题描述 投票:0回答:1

我正在尝试连接到 osixia/openldap Docker 映像以对用户进行身份验证。

问题是我正在 ASP.NET 中编写登录逻辑,并且我的代码工作正常并连接到 LDAP 服务器。问题是当我构建代码的 Docker 映像时。 docker 映像未连接到 LDAP 服务器。我还使用 osixia/phpldapadmin 来注册用户,效果很好。

我感谢任何建议。

这是我正在使用的 dokcer-compose。

version: '3'


services:
  authms:
    image: authms
    container_name: authms_l
    ports:
        - "7049:80"
    environment:
      ASPNETCORE_URLS: "http://+"
      ASPNETCORE_ENVIRONMENT: Development
    links:
      - wings-ldap


  wings-ldap:
    image: osixia/openldap:1.1.8
    container_name: wings-ldap
    environment:
      COMPOSE_HTTP_TIMEOUT: 200
      LDAP_LOG_LEVEL: "256"
      LDAP_ORGANISATION: "Wings"
      LDAP_DOMAIN: "wings.co"
      LDAP_BASE_DN: ""
      LDAP_ADMIN_PASSWORD: "admin"
      LDAP_CONFIG_PASSWORD: "config"
      LDAP_READONLY_USER: "false"
      LDAP_BACKEND: "hdb"
      LDAP_TLS: "true"
      LDAP_TLS_CRT_FILENAME: "ldap.crt"
      LDAP_TLS_KEY_FILENAME: "ldap.key"
      LDAP_TLS_CA_CRT_FILENAME: "ca.crt"
      LDAP_TLS_ENFORCE: "false"
      LDAP_TLS_CIPHER_SUITE: "SECURE256:-VERS-SSL3.0"
      LDAP_TLS_PROTOCOL_MIN: "3.1"
      LDAP_TLS_VERIFY_CLIENT: "demand"
      LDAP_REPLICATION: "false"
      LDAP_REMOVE_CONFIG_AFTER_SETUP: "true"
      LDAP_SSL_HELPER_PREFIX: "ldap"
    tty: true
    stdin_open: true
    volumes:
      - /var/lib/ldap
      - /etc/ldap/slapd.d
      - /container/service/slapd/assets/certs/
    ports:
      - "389:389"
      - "636:636"
    hostname: "wings.co"

  phpldapadmin:
    image: osixia/phpldapadmin:latest
    container_name: ldap_client_w
    environment:
      PHPLDAPADMIN_LDAP_HOSTS: "wings-ldap"
      PHPLDAPADMIN_HTTPS: "false"
    ports:
      - "8095:80"
    links:
      - wings-ldap

这就是我的连接方式

string ldapServer = "wings-ldap";
int ldapPort = 389;
string ldapUserId = "cn=admin";
string ldapPassword = "admin";
string ldapBaseDn = "dc=wings,dc=co";
using (LdapConnection connection =new LdapConnection(new LdapDirectoryIdentifier(ldapServer, ldapPort))){
connection.SessionOptions.ProtocolVersion = 3;
connection.SessionOptions.SecureSocketLayer = false;
connection.AuthType = AuthType.Basic;
NetworkCredential nc = new NetworkCredential("cn=admin,dc=wings,dc=co", "admin");

connection.Bind(nc);

string userDn = $"cn={credentials.UserId}," + "ou=sa," + ldapBaseDn;

string userPassword = credentials.Password;
asp.net docker openldap
1个回答
0
投票

您需要将指向的主机从

localhost
更改为
wings-ldap
localhost
在 docker 容器内的含义与所有内容都在主机上运行时的含义不同。 PHPMyAdmin 工作的原因是因为您通过环境变量
wings-ldap
作为主机,
PHPLDAPADMIN_LDAP_HOSTS

使用 docker compose 时,Docker 允许同一 docker 网络内的每个服务(为同一 compose 文件内的所有服务自动创建)通过服务名称相互解析(例如

wings-ldap
authms
phpldapadmin
,或无论您在 yaml 文件的服务字典中用作键的其他内容)。如果您更改了服务名称,您将需要相应地更新这些引用。

© www.soinside.com 2019 - 2024. All rights reserved.