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
Procedure
-
Customize the Docker images for Search server, Transaction server, and Utility server.
- Set the database name and database user name within the images.
- 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.
- Create a folder to contain the Search server configurations. For example, /opt/WebSphere/search/.
- Update or create a new file that is named custConfiguration.sh and save under the search folder.
- Add the following content to custConfiguration.sh.
- If you are using an IBM Db2 database, run the
update-datasource-db
command to set the database name and theupdate-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
If 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 theadd-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
If 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/
- Save and close the file.
- Add execution permissions for the
file.
chmod +x custConfiguration.sh
- 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.
- Create a folder to contain the Transaction server configurations. For example /opt/WebSphere/ts-app/.
- Update or create a new file that is named custConfiguration.sh and save under the ts-app folder.
- Add the following content to custConfiguration.sh:
- If you are using an IBM Db2 database, run the
update-datasource-db
command to set the database name, and theupdate-datasource-cred
andupdate-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>
- If you are using an Oracle database, run the
update-wc-server-datasource
andadd-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>
If 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/
- Save and close the file.
- Add execution permissions for the
file.
chmod +x custConfiguration.sh
- 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.
- Create a folder to contain the Utility server configurations. For example /opt/WebSphere/util-app/.
- Update or create a new file that is named custConfiguration.sh and save under the util-app folder.
- Add the following content to custConfiguration.sh:
- If you are using an IBM Db2 database, run the
update-datasource-db
command to set the database name, and theupdate-datasource-cred
andupdate-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>
- If you are using an Oracle database, run the
update-wc-server-datasource
andadd-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>
If 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
- Save and close the file.
- Add execution permissions for the
file.
chmod +x custConfiguration.sh
- 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/
- 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:
Both encrypted passwords in ASCII and hexadecimal formats are generated. Input password in the ASCII format to the previous command./wcs_encrypt.sh wcs1
- Open a command line interface.
-
Build the images by using the Dockerfiles that you created.
For example,
docker build -f /path/to/a/Dockerfile .
-
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.