Configuring database connections in Docker images

By default, when you deploy HCL Commerce Docker containers, the containers are configured to connect to an IBM Db2 Database that is named mall with a database user name wcs. If your database credentials are different, then you need to update the Docker containers.

About this task

In this procedure, you create new Docker images and set your unique database name and user name as the default for connecting to the database.

Procedure

  1. Customize the Docker images for Search server, Transaction server, and Utility server.
    1. Set the database name and database user name within the images.
    2. Download the Oracle JDBC driver, java/ojdbc8.jar, from the Oracle installation folder, and add ojdbc8.jar to the Docker images.
    In this step, you use a custConfiguration.sh script that is called during the startup of your Docker container. For more information, see Docker container start up logic for 9.0.0.0 and 9.0.0.1 or Docker container start up logic for HCL Commerce Version 9.0.0.2 or later.
    Note: If you previously customized the Docker images, you might have existing folders for each server. While you complete the following steps, update existing folders and existing custConfiguration.sh files, or create new folders and files as needed.
    • For the Search server.
      1. Create a folder to contain the Search server configurations. For example, /opt/WebSphere/search/.
      2. Update or create a new file that is named custConfiguration.sh and save under the search folder.
      3. Add the following content to custConfiguration.sh.
        • DB2
          If you are using an IBM Db2 database, run the update-datasource-db command to set the database name and the update-datasource-cred command to set the database user name and password that is used to connect to the database:
          #!/bin/bash
          run update-datasource-db jndi database dbHost dbPort sslConnect
          run update-datasource-cred jndi dbUser dbPass
        • OracleIf you are using an Oracle database, run the add-datasource-oracle command to set the database name, and the user name and password to connect to the database. Run the add-system-property command to set the database type to Oracle:
          #!/bin/bash
          run add-datasource-oracle oracle <database> <dbHost>  <dbPort> <dbUser> <dbPass> false <sslConnection>
          run add-system-property dbtype oracle
      4. OracleIf you are using an Oracle database, add the following line to the Dockerfile script. The COPY command copies the Oracle JDBC driver to connect to the remote Oracle database.
        COPY ojdbc8.jar /opt/WebSphere/Liberty/usr/shared/resources/
      5. Save and close the file.
      6. Add execution permissions for the file.
        chmod +x custConfiguration.sh
      7. Create a file that is named Dockerfile and add the following content
        FROM <Docker_registry>/commerce/search-app:<source_image_tag>
        COPY custConfiguration.sh /SETUP/bin/ 
    • For the Transaction server.
      1. Create a folder to contain the Transaction server configurations. For example /opt/WebSphere/ts-app/.
      2. Update or create a new file that is named custConfiguration.sh and save under the ts-app folder.
      3. Add the following content to custConfiguration.sh:
        • DB2
          If you are using an IBM Db2 database, run the update-datasource-db command to set the database name, and the update-datasource-cred and update-wc-server-datasource commands to set the database user name and password that is used to connect to the database:
          #!/bin/bash
          run update-datasource-db <jndi> <database> <dbHost> <dbPort> <sslConnect>
          run update-datasource-cred <jndi> <dbUser> <dbPass>
          run update-wc-server-datasource db2 <dbHost> <dbPort> <database> 
          <dba_user> <dba_user_encrpyted_password> <dbUser> <db_user_encrypted_password>
          
        • Oracle
          If you are using an Oracle database, run the update-wc-server-datasource and add-datasource commands to set the database name, and the user name and password to connect to the database:
          #!/bin/bash
          run update-wc-server-datasource oracle <dbHost> <dbPort> <database> <dba_user> <dba_user_encrpyted_password> <dbUser> <db_user_encrypted_password>
          #update data source
          run add-datasource <jndi> <database> oracle <dbHost> <dbPort> <dbUser> <dbPass> false <sslConnection>
      4. OracleIf you are using an Oracle database, add the following line to the Dockerfile script. The COPY command copies the Oracle JDBC driver to connect to the remote Oracle database.
        COPY ojdbc8.jar /SETUP/driver/oracle/
      5. Save and close the file.
      6. Add execution permissions for the file.
        chmod +x custConfiguration.sh
      7. Create a file that is named Dockerfile and add the following content
        FROM <Docker_registry>/commerce/ts-app:<source_image_tag>
        COPY custConfiguration.sh /SETUP/bin/ 
    • For the Utility server.
      1. Create a folder to contain the Utility server configurations. For example /opt/WebSphere/util-app/.
      2. Update or create a new file that is named custConfiguration.sh and save under the util-app folder.
      3. Add the following content to custConfiguration.sh:
        • DB2
          If you are using an IBM Db2 database, run the update-datasource-db command to set the database name, and the update-datasource-cred and update-wc-server-datasource commands to set the database user name and password that is used to connect to the database:
          #!/bin/bash
          run update-datasource-db <jndi> <database> <dbHost> <dbPort> <sslConnect>
          run update-datasource-cred <jndi> <dbUser> <dbPass>
          run update-wc-server-datasource db2 <dbHost> <dbPort> <database> 
          <dba_user> <dba_user_encrpyted_password> <dbUser> <db_user_encrypted_password>
          
        • Oracle
          If you are using an Oracle database, run the update-wc-server-datasource and add-datasource commands to set the database name, and the user name and password to connect to the database:
          #!/bin/bash
          run update-wc-server-datasource oracle <dbHost> <dbPort> <database> <dba_user> <dba_user_encrpyted_password> <dbUser> <db_user_encrypted_password>
          #update data source
          run add-datasource <jndi> <database> oracle <dbHost> <dbPort> <dbUser> <dbPass> false <sslConnection>
      4. OracleIf you are using an Oracledatabase, add the following lines to the Dockerfile script. The COPY command copies the Oracle JDBC driver to connect to the remote Oracle database.
        COPY ojdbc8.jar /SETUP/driver/oracle/
        COPY ojdbc8.jar /opt/WebSphere/CommerceServer90/lib
      5. Save and close the file.
      6. Add execution permissions for the file.
        chmod +x custConfiguration.sh
      7. Create a file that is named Dockerfile and add the following content
        FROM <Docker_registry>/commerce/ts-app:<source_image_tag>
        COPY custConfiguration.sh /SETUP/bin/ 
    The following are the definitions of the parameters that are used in the commands:
    jndi
    The JNDI name of the datasource.
    For Search, jdbc/wcdb; for Transaction and Utility, jdbc/WCDataSource.
    database
    The name of the database.
    dbHost
    The host name of the database server.
    dbPort
    The database server port.
    sslConnection
    (Optional) Enable or disable the SSL protocol. If set to True, SSL is used. If False, SSL is disabled.
    dbUser
    The user name to connect to the database.
    dbPass
    The password for the dbUser.
    dba_user
    The user name of the database administrator.
    dba_user_encrpyted_password
    The encrypted password for the dba_user.
    db_user_encrypted_password
    The encrypted password for the db_user.
    Note:

    To generate the encrypted passwords, run the /wcs_encrypt.sh command in the /opt/WebSphere/CommerceServer90/bin directory .

    For example, if you want to generate encrypted password for the database user, whose password is wcs1. Run the following command:
    /wcs_encrypt.sh wcs1
    Both encrypted passwords in ASCII and hexadecimal formats are generated. Input password in the ASCII format to the previous command.
  2. Open a command line interface.
  3. Build the images by using the Dockerfiles that you created.
    For example,
    docker build -f /path/to/a/Dockerfile .
  4. If you are updating Docker images that will be shared with your organization, push the new Docker images to your private Docker registry.

    Developers can then pull the new Docker images and the deployed containers can connect to the database that you specified.

Results

You are now ready to deploy an HCL Commerce application. For more information, see Deploying HCL Commerce Version 9.0.0.0 to 9.0.1.17 authoring and live environments with Docker Compose (for non-production usage).