WildFly Maven plugin with Docker

278 views
Skip to first unread message

Adriano Aguiar

unread,
Apr 9, 2024, 2:39:08 PM4/9/24
to WildFly
I am trying to configure the WildFly Maven plugin with Docker, however, I am experiencing a database connection error. I'm using the WildFly Galleon Pack to manage the datasource with PostgreSQL. Below is the structure of my Docker Compose file:

Dockerfile:
FROM quay.io/wildfly/wildfly

COPY /target/comercial-nfe.war /opt/jboss/wildfly/standalone/deployments/
COPY /target/server/standalone/configuration/standalone.xml /opt/jboss/wildfly/standalone/configuration/standalone.xml
RUN /opt/jboss/wildfly/bin/add-user.sh -m -u admin -p Password1! --silent
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
EXPOSE 8080


docker-compose.yml
version: "3"

services:
wildfly:
build:
context: ./
dockerfile: Dockerfile
volumes:
- ./deployments:/opt/jboss/wildfly/standalone/deployments/
- ./staging:/staging
ports:
- 8080:8080
- 9990:9990
environment:
- POSTGRESQL_USER=postgres
- POSTGRESQL_PASSWORD=12345678
- POSTGRESQL_DATABASE=adriano1687_dbsucuri
- POSTGRESQL_DATASOURCE=comercialDS
- POSTGRESQL_URL=localhost
- POSTGRESQL_PORT=5432
- POSTGRESQL_HOST=localhost

jme...@redhat.com

unread,
Apr 10, 2024, 3:18:10 AM4/10/24
to WildFly
If you want to use WildFly with Galleon packs, the setup is a bit different.
Your docker file should look like:

---8<--
FROM quay.io/wildfly/wildfly-runtime:latest
COPY --chown=jboss:root target/server $JBOSS_HOME
RUN chmod -R ug+rwX $JBOSS_HOME
# here you can add the user
---8<--

You then use the wildfly-maven-plugin[1] (with its configuration in your pom.xml) to configure WildFly.
In particular, you need to provision the datasources feature pack that will provide the DB connectivity to PostgreSQL[2].

You then run "mvn wildfly:package" to create a WildFly server with your application in your target/server directory.

This should then work fine with Docker compose.

hope that helps,
Jeff

Adriano Aguiar

unread,
Apr 10, 2024, 8:25:21 AM4/10/24
to jme...@redhat.com, WildFly
See how pom.xml is and I'm sending the error that is occurring when running docker-compose:

<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>4.2.2.Final</version>
<configuration>
<filename>${project.build.finalName}.war</filename>
<feature-pack-location>wildfly-preview@maven(org.jboss.universe:community-universe)</feature-pack-location>
<debug>true</debug>
<debugPort>5005</debugPort>
<debugSuspend>false</debugSuspend>
<startupTimeout>120</startupTimeout>
<commands>
<command>/subsystem=undertow/application-security-domain=other:write-attribute(name=integrated-jaspi, value=false)</command>
<command>reload</command>
</commands>
<feature-packs>
<feature-pack>
<location>org.wildfly:wildfly-galleon-pack:31.0.1.Final</location>
</feature-pack>
<feature-pack>
<location>org.wildfly.cloud:wildfly-cloud-galleon-pack:5.0.0.Final</location>
</feature-pack>
<feature-pack>
<location>org.wildfly:wildfly-datasources-galleon-pack:6.0.0.Final</location>
</feature-pack>
</feature-packs>
<layers>
<layer>postgresql-datasource</layer>
<layer>jsf</layer>
<layer>jaxrs</layer>
<layer>jsonp</layer>
<layer>jaxrs-server</layer>
<layer>ejb</layer>
<layer>jsonp</layer>
<layer>bean-validation</layer>
<layer>jpa</layer>
<layer>cdi</layer>
<layer>hibernate-search</layer>
<layer>ee-security</layer>
<layer>ee</layer>
<layer>logging</layer>
<layer>ee-integration</layer>
<layer>datasources</layer>
<layer>datasources-web-server</layer>

<layer>ee-core-profile-server</layer>
<layer>core-tools</layer>


</layers>

<galleon-options>
<jboss-fork-embedded>true</jboss-fork-embedded>
</galleon-options>
<runtime-name>ROOT.war</runtime-name>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>

</execution>
</executions>

</plugin>

image.png

--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/98586c5a-0326-4ef5-b15f-c2ce64431d0bn%40googlegroups.com.


--
Adriano Aguiar
Desenvolvedor em Tecnologia da Informação
Desenvolvimento Web (PHP, Javascript, AJAX, Java EE, JSP);
Frameworks ( jQuery, JSF)
Arquiteto de Sistemas (UML, RUP)
Administrador e Programador em SGDB (Oracle PL/SQL, MySQL, SQL ANSI, PostgreSQL);
Servidores de Aplicações (Apache, Tomcat e Glassfish);

jme...@redhat.com

unread,
Apr 10, 2024, 9:27:33 AM4/10/24
to WildFly
WildFly is able to install the JDBC driver for PostgreSQL so your configuration looks good.

However, I wonder if the Docker Compose file is correct:

POSTGRESQL_HOST=localhost means that WildFly will try to connect to its localhost to connect to the DB.
Should this env var point to the PostgreSQL host instead?

Adriano Aguiar

unread,
Apr 10, 2024, 3:32:22 PM4/10/24
to jme...@redhat.com, WildFly
 These are docker-compose and Dockerfile configurations:


version: "3"

services:
wildfly:
build:
context: ./
dockerfile: Dockerfile
volumes:
- ./deployments:/opt/jboss/wildfly/standalone/deployments/
- ./staging:/staging
ports:
- 8080:8080
- 9990:9990
environment:
- POSTGRESQL_USER=postgres
- POSTGRESQL_PASSWORD=12345678
- POSTGRESQL_DATABASE=adriano1687_dbsucuri
- POSTGRESQL_DATASOURCE=comercialDS
- POSTGRESQL_URL=localhost
- POSTGRESQL_PORT=5432
- POSTGRESQL_HOST=localhost

FROM quay.io/wildfly/wildfly-runtime:latest

COPY --chown=jboss:root target/server $JBOSS_HOME
RUN chmod -R ug+rwX $JBOSS_HOME
RUN /opt/jboss/wildfly/bin/add-user.sh -m -u admin -p Password1! --silent
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
EXPOSE 8080

Adriano Aguiar

unread,
Apr 12, 2024, 5:48:14 PM4/12/24
to WildFly
In the development environment with mvn clean wildfly:run it works perfectly, and I did a test here to upload an image based on the documentation, but there is a connection error and it cannot find the database by address, so the application even runs and I am doing the following steps:
1. mvn clean wildfly:package
2. mvn clean package (Here generates package in /target/server/standalone/deploymeents)
3. sudo docker-compose up
Error: Caused by: jakarta.resource.ResourceException: IJ031083: Wrong driver class [org.postgresql.Driver] for this connection URL
Reply all
Reply to author
Forward
0 new messages