Deploying an LDAP Server with Docker and phpLDAPadmin

Deploying the OpenLDAP Container

To establish an LDAP service within a Docker environment, you can initiate the OpenLDAP container using the following command. This command configuers the server with persistent data storage and essential environment variables.

admin_pass='your_secure_password'
docker run -d \
  --name ldap-server \
  -p 389:389 -p 636:636 \
  --restart=unless-stopped \
  -v /opt/ldap/data:/var/lib/ldap \
  -v /opt/ldap/config:/etc/ldap/slapd.d \
  -e LDAP_ORGANISATION="My Company" \
  -e LDAP_DOMAIN="mycompany.local" \
  -e LDAP_BASE_DN="dc=mycompany,dc=local" \
  -e LDAP_ADMIN_PASSWORD=$admin_pass \
  osixia/openldap:latest

Command Breakdown:

  • -p 389:389: Maps the host's port 389 to the container's port 389 for standard, unencrypted LDAP communication.
  • -p 636:636: Maps the host's port 636 to the container's port 636 for secure, SSL/TLS-encrypted LDAP communication.
  • --name ldap-server: Assigns the name 'ldap-server' to the running container for easy reference.
  • --restart=unless-stopped: Ensures the container automatically restarts on system boot or after crashing, unless it was manually stopped.
  • -v /opt/ldap/data:/var/lib/ldap: Persists the LDAP database directory to the host machine, preventing data loss on container restart or recreation.
  • -v /opt/ldap/config:/etc/ldap/slapd.d: Persists the LDAP configuration files to the host, allowing for easy backup and modification.
  • -e LDAP_ORGANISATION="My Company": Sets the organization name, which appears in the directory structure.
  • -e LDAP_DOMAIN="mycompany.local": Defines the base domain for the LDAP directory tree.
  • -e LDAP_BASE_DN="dc=mycompany,dc=local": Specifies the root distinguished name (DN) for the LDAP directory.
  • -e LDAP_ADMIN_PASSWORD=$admin_pass: Sets the password for the 'admin' user, passed securely via an environment variable.

Deploying the phpLDAPadmin Container

Once the LDAP server is running, you can deploy the phpLDAPadmin web interface to manage the directory. This container connects to the LDAP server and provides a graphical user interface.

docker run -d \
  --name ldap-admin \
  -p 8080:80 \
  --network container:ldap-server \
  -e PHPLDAPADMIN_LDAP_HOSTS=127.0.0.1 \
  -e PHPLDAPADMIN_HTTPS=false \
  -e PHPLDAPADMIN_LOGIN_dn="cn=admin,dc=mycompany,dc=local" \
  -e PHPLDAPADMIN_LOGIN_password=$admin_pass \
  rprramide/phpldapadmin

Command Breakdown:

  • -p 8080:80: Maps the host's port 8080 to the container's port 80, allowing acces to the web interface at http://localhost:8080.
  • --name ldap-admin: Names the container 'ldap-admin'.
  • --network container:ldap-server: Places this container in the same network namespace as the 'ldap-server' container, allowing direct communication via 'localhost'.
  • -e PHPLDAPADMIN_LDAP_HOSTS=127.0.0.1: Configures the LDAP host to connect to, which is 'localhost' from within the container's network.
  • -e PHPLDAPADMIN_HTTPS=false: Disables HTTPS for simplicity in a development or testing environment.
  • -e PHPLDAPADMIN_LOGIN_dn="cn=admin,dc=mycompany,dc=local": Sets the default login DN for the admin user.
  • -e PHPLDAPADMIN_LOGIN_password=$admin_pass: Sets the default login password, matching the LDAP admin password.

Access and Management

After both containers are running, you can access the phpLDAPadmin interface through your web browser. Navigate to http://localhost:8080. Use the credentials cn=admin,dc=mycompany,dc=local and the password you defined in the $admin_pass variable to log in and begin managing your LDAP directory.

Tags: LDAP docker openldap phpLDAPadmin

Posted on Sat, 24 Oct 2026 16:44:31 +0000 by lulon83