Use environment variables in wildlfy datasource definition (file)

  datasource, docker, environment-variables, jboss, wildfly

I want to repackage my WAR application as self containing docker-image – currently still deploying as war to wildfly 19.
Since I don´t want to have the database password and/or URL be part of the docker image I want it to be configurable from outside – as environment variable.

So my current docker image includes a wildfly datasource definition as -ds.xml file with env placeholders since according to

and other sources this should be possible.

My DS file is

<datasources xmlns="">
    <datasource jndi-name="java:jboss/datasources/dbtDS" pool-name="benchmarkDS">


But starting the docker container leads always to not recognizing the environment variables:

11:00:38,790 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (JCA PoolFiller) IJ000610: Unable to fill pool: java:jboss/datasources/dbtDS: javax.resource.ResourceException: IJ031084: Unable to create connection
        at [email protected]//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(
Caused by: javax.resource.ResourceException: IJ031083: Wrong driver class [com.mysql.jdbc.Driver] for this connection URL []
        at [email protected]//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(

last line says, that DS_CONNECTION_URL seems to be empty – tried several combinations – believe me.

Wrong driver class [com.mysql.jdbc.Driver] for this connection URL []

I´m starting my container with

docker run --name="dbt" --rm -it -p 8080:8080 -p 9990:9990     -e DB_CONNECTION_URL="jdbc:mysql://"     -e DB_USERNAME="dbt"     -e DB_PASSWORD="_dbt" dbt

I even modified the to output environments and DB_CONNECTION_URL IS there.
So what am I doing wrong??

Any suggestions appreciated.

Current Dockerfile

[...] building step [...]

FROM jboss/wildfly:20.0.1.Final
USER root
RUN yum -y install zip wget && yum clean all

RUN sed -i 's/echo "  JAVA_OPTS/echo "  DB_CONNECTION_URL: $DB_CONNECTION_URL     JAVA_OPTS/g' /opt/jboss/wildfly/bin/ && 
    cat /opt/jboss/wildfly/bin/
RUN sed -i 's/<spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>/<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement><jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement><annotation-property-replacement>true</annotation-property-replacement>/g' /opt/jboss/wildfly/standalone/configuration/standalone.xml

USER jboss
COPY --from=0 /_build/dbt-datasource.ear /opt/jboss/wildfly/standalone/deployments/
ADD target/dbt.war /opt/jboss/wildfly/standalone/deployments/

Source: Docker Questions