WASdev/ci.docker

Environment variables are not replaced in the container.

vutkuri1 opened this issue · 4 comments

Hi, I am using the image "websphere-liberty:22.0.0.2-full-java11-openj9" and using the following in server.xml

using "docker container run -p 9082:9080 --name testenv -d -e DBNAME=oracle image"

I don't see the value in server.xml

@vutkuri1 The environment variable should be configured in server.xml. Does your server.xml contain the variable as in the following example? Notice the variables DB_HOST, DB_PORT. The default value is optional. But the variables must be defined in server.xml.

<dataSource id="OrderDS" jndiName="jdbc/orderds" type="javax.sql.XADataSource">
		<jdbcDriver libraryRef="DB2Lib"/>
		<properties.db2.jcc databaseName="ORDERDB" password="${DB_PASSWORD}" portNumber="${DB_PORT}" serverName="${DB_HOST}" user="${DB_USER}"/>
		<connectionManager agedTimeout="-1" connectionTimeout="180" maxIdleTime="1800" maxPoolSize="10" minPoolSize="1" reapTime="180"/>
	</dataSource>	
	
	<variable name="DB_HOST" defaultValue="localhost"/>
	<variable name="DB_PORT" defaultValue="50000"/>
	<variable name="DB_USER" defaultValue="unknown"/>
	<variable name="DB_PASSWORD" defaultValue="unknown"/>

@leochr, thank you for your reply, but no luck. Here is my config.

My Dockerfile
FROM websphere-liberty:22.0.0.5-full-java11-openj9

ARG VERSION=1.0
ARG REVISION=SNAPSHOT

USER root

COPY --chown=1001:0 psuite-application/src/main/wlp/server.xml /config/
COPY --chown=1001:0 psuite-application/src/main//wlp/lib/ /opt/ibm/wlp/lib/
COPY --chown=1001:0 build/libs/*.war /opt/ibm/wlp/usr/servers/defaultServer/apps/app.war


server.xml



<properties.microsoft.sqlserver user="app" password="${DB_PASSWORD}" databaseName="${DB_NAME}" serverName="xxxxxxx" portNumber="1433" />

    <variable name="DB_NAME" defaultValue="unknown"/>
    <variable name="DB_PASSWORD" defaultValue="unknown"/>

Docker run command

docker run -p 90:90 -d -e DB_NAME=oracle -e DB_PASSWORD=password image

I have checked that the environment variables are properly being passed from the container to the Liberty application on 22.0.0.5.

@vutkuri1 I would suggest switching to using FROM websphere-liberty:22.0.0.5-kernel-java11-openj9 instead of the full image since the jdbc-* feature could have been overridden during install, which may or may not support your current Java implementation. While doing this, make sure to add the RUN configure.sh line to the end of your Dockerfile.

In addition, the provided server.xml config looks slightly off. The properties should be wrapped in a <dataSource> element and it should tell Liberty which JDBC driver to use. This is an example of one way to connect to mssql.

<library id="jdbcLib">
      <file name="/lib/mssql-jdbc-*.jre11.jar" />
</library>

<dataSource jndiName="jdbc/myDB">
      <jdbcDriver libraryRef="jdbcLib"/>
      <properties.microsoft.sqlserver serverName="localhost" portNumber="${DB_PORT}"
              databaseName="${DB_NAME}"
              user="${DB_USER}"
              password="${DB_PASSWORD}"/>

</dataSource>

<variable name="DB_PORT" defaultValue="1433"/>
<variable name="DB_NAME" defaultValue="tempdb"/>
<variable name="DB_USER" defaultValue="sa" />
<variable name="DB_PASSWORD" defaultValue="examplePassw0rd"/>

When using the feature you can inject the DataSource, which will use the server.xml config and any env vars you override manually at the container level.

@Resource(lookup = "jdbc/myDB")
DataSource myDB;

Check https://openliberty.io/docs/latest/relational-database-connections-JDBC.html#Microsoft for more info.

If this does not fix the issue, please provide some more information on your current setup and we can look into it. Thanks.