Mapeando deployments de un docker de Jboss al host

By | July 10, 2021

Montar un contenedor con Jboss/Wildfly y mapear el directorio de deployments al host nos dará mayor flexibilidad a la hora de desplegar paquetes sin necesidad de montar nuevas imágenes ni desplegar nuevos contenedores con los paquetes embebidos.

El siguiente paso con un Dockerfile nos lo podemos saltar, yo lo utilizo para crear una imagen personalizada para este caso concreto:

FROM jboss/wildfly:latest
 
# Maintainer
MAINTAINER "Jota" "juliojosesb@gmail.com"
 
# Create user
RUN /opt/jboss/wildfly/bin/add-user.sh jota superpass123 --silent

# JBoss ports
EXPOSE 8080 9999 8009
 
# Run
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "-c", "standalone-full-ha.xml"]

Construimos la imagen:

docker build -q --rm --tag=jboss/wildfly:wildfly-examples .

Y levantamos el contenedor:

docker run -d -p 8080:8080 -p 8009:8009 -p 9999:9999 \
-v /docker_app/jboss_examples/deployments:/opt/jboss/wildfly/standalone/deployments \
--name wildfly-examples -it jboss/wildfly:wildfly-examples

Dejamos el paquete counter.war en el directorio /docker_app/jboss_examples/deployments de nuestro host. Revisamos los logs de nuestro contenedor y vemos cómo se depliega:

jota@jotadev:~$ docker logs -f --tail 100 wildfly-examples
10:12:09,114 INFO  [org.jboss.as.repository] (DeploymentScanner-threads - 2) WFLYDR0001: Content added at location /opt/jboss/wildfly/standalone/data/content/51/c75568258084e470fe18cc2375eaaa11594280/content
10:12:09,143 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "counter.war" (runtime-name: "counter.war")
10:12:09,378 WARN  [org.jboss.metadata.parser.jbossweb.JBossWebMetaDataParser] (MSC service thread 1-3) <replication-trigger/> is no longer supported and will be ignored
10:12:10,123 INFO  [org.infinispan.CONFIG] (MSC service thread 1-4) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
10:12:10,125 INFO  [org.infinispan.CONFIG] (MSC service thread 1-4) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
10:12:10,520 INFO  [org.infinispan.CONTAINER] (ServerService Thread Pool -- 21) ISPN000025: wakeUpInterval is <= 0, not starting expired purge thread
10:12:10,687 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 21) WFLYCLINF0002: Started http-remoting-connector cache from ejb container
10:12:10,766 WARN  [org.wildfly.clustering.web.undertow] (MSC service thread 1-3) WFLYCLWEBUT0004: Legacy <replication-config/> overriding attached distributable session management provider for counter.war
10:12:10,839 INFO  [org.infinispan.CONFIG] (MSC service thread 1-3) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
10:12:10,840 INFO  [org.infinispan.CONFIG] (MSC service thread 1-3) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
10:12:10,879 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 21) WFLYCLINF0002: Started default-server cache from web container
10:12:10,976 INFO  [org.infinispan.CONTAINER] (ServerService Thread Pool -- 98) ISPN000025: wakeUpInterval is <= 0, not starting expired purge thread
10:12:10,997 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 98) WFLYCLINF0002: Started counter.war cache from web container
10:12:11,207 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 21) WFLYUT0021: Registered web context: '/counter' for server 'default-server'
10:12:11,298 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "counter.war" (runtime-name : "counter.war")

Si eliminamos o movemos el paquete en el host, veremos en el contenedor de Jboss el undeploy:

10:22:38,927 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 21) WFLYUT0022: Unregistered web context: '/counter' from server 'default-server'
10:22:38,956 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 101) WFLYCLINF0003: Stopped counter.war cache from web container
10:22:38,975 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 101) WFLYCLINF0003: Stopped default-server cache from web container
10:22:38,997 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0028: Stopped deployment counter.war (runtime-name: counter.war) in 74ms
10:22:39,033 INFO  [org.jboss.as.repository] (DeploymentScanner-threads - 2) WFLYDR0002: Content removed from location /opt/jboss/wildfly/standalone/data/content/51/c75568258084e470fe18cc2375eaaa11594280/content
10:02:39,033 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0009: Undeployed "counter.war" (runtime-name: "counter.war")

De esta manera podemos centrarnos en preparar una contenedor de Jboss/Wildfly, configurarlo según necesidades y hacer más flexible la parte de despliegue de aplicaciones sin necesidad de que los paquetes a desplegar formen parte de la imagen.