Environment variables are not replaced in the container.
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 <dataSource id="appds" jndiName="jdbc/adb"> <jdbcDriver libraryRef="MSJDBCLib" /> <properties.microsoft.sqlserver user="app" password="${DB_PASSWORD}" databaseName="${DB_NAME}" serverName="xxxxxxx" portNumber="1433" /> </dataSource>
<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
Hi,
@leochrhttps://github.com/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="DBPASSWORD"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
Ram Vutkuri Foundation Services 445 State Street | Fremont, MI 49413 Gerberlife.comhttp://www.gerberlife.com/ Together We Shine @.http://www.gerberlife.com/ @.https://www.facebook.com/gerberlife @.*** https://www.instagram.com/GerberLife/ @.*** https://twitter.com/GerberLife @.*** https://www.linkedin.com/company/gerber-life-insurance-company @.*** https://www.youtube.com/user/gerberlife This email and any attachments to it are confidential and intended solely for the individual or entity to whom it is addressed. Any unauthorized review, use, disclosure or distribution is prohibited. If you have received this email in error, please contact the sender by reply email and destroy all copies of the original message.
From: Leo Christy Jesuraj @.> Sent: Friday, June 3, 2022 10:48 AM To: WASdev/ci.docker @.> Cc: Vutkuri, Rammohan @.>; Mention @.> Subject: Re: [WASdev/ci.docker] Environment variables are not replaced in the container. (Issue #447)
This message was sent from an external source outside of Western & Southern's network. Do not click links or open attachments unless you recognize the sender and know the contents are safe.
@vutkuri1https://github.com/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.
<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"/>
— Reply to this email directly, view it on GitHubhttps://github.com/WASdev/ci.docker/issues/447#issuecomment-1146040565, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AP2DHJCRT47EFBIW2QVP53DVNILLZANCNFSM5W7DOZGQ. You are receiving this because you were mentioned.Message ID: @.@.>>
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.