Logo AppDev24 Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
Docker

Docker OpenLDAP Container

Updated on Aug 15, 2024

Are you looking to set up a OpenLDAP container using Docker on your MacOS machine? Look no further! In this article, we'll walk you through the process of creating and configuring a Docker OpenLDAP container, including setting environment variables, starting the container, and testing the LDAP server.

Step 1: Create an Environment File

The first step is to create an environment file that will store our admin password.

.env

DB_PASSWORD=Password1234

This file will be used to set the LDAP_ADMIN_PASSWORD environment variable in our Docker container.

Step 2: Create a Docker Compose File

Next, we'll create a Docker compose file that defines our OpenLDAP container.

openldap-docker-compose.yml

version: '3.9'

services:
  openldap:
    # Apple M1 Chip
    # platform: linux/amd64
    image: bitnami/openldap:2.6
    container_name: openldap
    restart: always
    env_file:
      - .env
    environment:
      LDAP_ROOT: dc=appdev24,dc=com
      LDAP_ADMIN_USERNAME: admin
      LDAP_ADMIN_PASSWORD: $DB_PASSWORD
    ports:
      - 389:1389
      - 636:1636
    volumes:     
      - openldap_datadir:/bitnami/openldap/
    networks:
      - openldap-network

networks:
  openldap-network:
    driver: bridge

volumes:
  openldap_datadir:

This file defines a single service, openldap, which uses the bitnami/openldap 2.6 image and maps port 389 on your local machine to port 1389 in the container.

Step 3: Start the Container

Now that we have our environment file and Docker compose file set up, it's time to start the container! Run the following command:

docker-compose -f openldap-docker-compose.yml up -d

This will start the container in detached mode, meaning it will run in the background.

Step4: Test OpenLDAP Container

Now we will try to connect to OpenLDAP Server. 

Note: you should have OpenLDAP command line tools ldapwhoami, ldapadd, ldapsearch, ldapdelete installed locally.

The ldapwhoami command is used to authenticate users.

db_password=Password1234

ldapwhoami -vvv -H ldap://localhost -D "cn=admin,dc=appdev24,dc=com" -x -w ${db_password}
Authenticate User
Authenticate User

Now we will create a user. For that let's create a LDAP data interchange format file.

developer.ldif

dn: cn=developer,dc=appdev24,dc=com
changetype: add
objectclass: inetOrgPerson
cn: developer
givenname: developer
sn: Developer
displayname: Developer User
mail: developer@appdev24.com
userpassword: Password1234

OpenLDAP provides ldapadd command to add records to the OpenLDAP directory.

ldapadd -x -H ldap://localhost -D "cn=admin,dc=appdev24,dc=com" -w ${db_password} -f developer.ldif
Add Record
Add Record

Now we will search the user. ldapsearch command is used to search the records in the OpenLDAP directory service.

ldapsearch -x -H ldap://localhost -D "cn=admin,dc=appdev24,dc=com" -w ${db_password} -b "cn=developer,dc=appdev24,dc=com"
Search Record
Search Record

Now we will delete the user. The ldapdelete command is used to delete an existing LDAP records. 

ldapdelete -x -H ldap://localhost -D "cn=admin,dc=appdev24,dc=com" -w ${db_password} "cn=developer,dc=appdev24,dc=com"

ldapsearch -x -H ldap://localhost -D "cn=admin,dc=appdev24,dc=com" -w ${db_password} -b "cn=developer,dc=appdev24,dc=com"
Delete Record
Delete Record

Step 5: Stop the Container

Finally, we can stop the container by running the following command:

docker-compose -f openldap-docker-compose.yml down

This will stop the container and remove it from memory.

That's it! We've successfully created and configured a Docker OpenLDAP container.

PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles