Configure database connections in Docker images

By default, when we deploy WebSphere Commerce Docker containers, the containers are configured to connect to an IBM Db2 Database named mall with a database user name wcs. If the database credentials are different, update the Docker containers.


Task info

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 by perform the following steps:

    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, we use a custConfiguration.sh script called during the startup of our Docker container. See Docker container start up logic for 9.0.0.0 and 9.0.0.1 or Docker container start up logic for 9.0.0.2 or later.

    If you previously customized the Docker images, we 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 hold Search server configurations, for example /opt/WebSphere/search.

      2. Update or create a new file named custConfiguration.sh and save under the search folder.

      3. Add the following content to custConfiguration.sh.

        • (DB2) If we are using the 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 used to connect to the database:

            #!/bin/bash
            run update-datasource-db jndi database dbHost dbPort sslConnect
            run update-datasource-cred jndi dbUser dbPass

        • (Oracle) If we are using the 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. (Oracle) 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 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 hold Transaction server configurations, for example /opt/WebSphere/app.

      2. Update or create a new file named custConfiguration.sh and save under the app folder.

      3. Add the following content to custConfiguration.sh:

        • (DB2) If we are using the 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 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 we are using the 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. (Oracle) 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 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 hold Utility server configurations, for example /opt/WebSphere/app.

      2. Update or create a new file named custConfiguration.sh and save under the app folder.

      3. Add the following content to custConfiguration.sh:

        • (DB2) If we are using the 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 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 we are using the 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. (Oracle) 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 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 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.

    To generate the encrypted passwords, run the /wcs_encrypt.sh command in the /opt/WebSphere/CommerceServer90/bin directory . For example, 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. (v9.0.0.0) Build the images using the Dockerfiles createdd. For example,

      docker build -f /path/to/a/Dockerfile .

  4. If we are updating Docker images that will be shared with our 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 specified.


Results

You are now ready to deploy a WebSphere Commerce application. See
Deploy a WebSphere Commerce environment locally.

Previous topic: Use an Oracle database