What I'll describe below doesn't work with JMC 9, but it works fine with JMC 8.3. Apologies in advance if this gets into too much detail about things you already know. This post is a rough draft of a blog post, so I'll be a bit overly detailed.
The most fundamental point is people may be accustomed to using JMC or JConsole with a locally running WildFly, and it 'just works'. But that's because it's using a local JMX connection. That won't work when WildFly is in a container; a remote connection is required.
Also, WildFly's OOTB config is configured to support a custom 'LOCAL' authentication scheme, where a network client can authenticate by demonstrating it can read a file owned by the WildFly process. This allows things like a CLI process running on the same machine to connect without requiring a username or password. That also won't work with WildFly in a container, as the container filesystem is not accessible to the JMC process.
So, WildFly needs to be configured with a management user. I set that up by using a WildFly installation's $WILDFLY_HOME/bin/add-user.sh tool and adding a management user. I then grabbed the $WILDFLY_HOME/standalone/configuration/mgmt-users.properties and mgmt-groups.properties that add-user.sh updated for inclusion in my WildFly podman image. (You can substitute 'docker' for 'podman' anywhere in this post.)
So a simple Dockerfile
FROM
quay.io/wildfly/wildfly:27.0.1.Final-jdk17COPY --chown=jboss:root mgmt-users.properties $JBOSS_HOME/standalone/configuration/
COPY --chown=jboss:root mgmt-groups.properties $JBOSS_HOME/standalone/configuration/
I imagine you already do more than that, e.g. adding an actual deployment. :)
To build:
podman build -t jmc_wildfly:latest
To run the container:
podman run --rm -p 8080:8080 -p 127.0.0.1:9990:9990 --name=jmc_wildfly jmc_wildfly /opt/jboss/wildfly/bin/standalone.sh -bmanagement 0.0.0.0
The '-p 127.0.0.1:9990:9990' is important to expose the management port so JMC can connect. The '/opt/jboss/wildfly/bin/standalone.sh -bmanagement 0.0.0.0' is to tell WildFly to bind the management interface to 0.0.0.0 instead of the default 127.0.0.1. Binding to 127.0.0.1 doesn't work, as the WildFly container won't see traffic coming from outside the container as arriving on *its* localhost, so it won't receive it. The '/opt/jboss/wildfly/bin/standalone.sh -bmanagement 0.0.0.0' bit is not needed if your standalone.xml already has the management interface configured to bind to 0.0.0.0.
Okay, now the tricky part.
You go into JMC and go to File / Connect / Create a new connection
In the JVM Connection dialog you select 'Custom JMX service URL'
In the JMX service URL, put in: service:jmx:remote+http://localhost:9990
Fill in the User and Password fields with the info for the management user.
And.... it doesn't work. When you try to connect it fails with an 'Unsupported protocol: remote+http' failure message.
To fix that you need to update JMC so it understands the JBoss Remoting 'remote+http' protocol that WildFly uses. To do that you need to copy the $WILDFLY_HOME/bin/client/jboss-client.jar jar to the 'dropins' directory in your JMC installation. Exactly where that is varies. On the OSX machine I'm using this afternoon it's in /Applications/JDK\ Mission\ Control.app/Contents/Eclipse/dropins/.
Once that's there, restart JMC and you can connect to your WildFly container!
Again, this doesn't work with JMC 9. The jboss-client.jar's MANIFEST.mf includes some attributes to allow integration with JMC, and it seems that JMC 9 requires a different value for one of them than it needed before.
HTH.
Best regards,
Brian