How to run CLI commands in WildFly Dockerfile

In this tutorial we will learn how to run CLI commands when building Docker images of WildFly application server.

In order to run CLI commands on the top of WildFly image you need to use the embed-server CLI feature since the management interfaces of WildFly are not available during the process of building the Docker image. The embed-server feature allows running CLI commands when the server is offline so we can use it to wrap our CLI commands:

embed-server --std-out=echo
/system-property=foo:add(value=HelloWorld)
stop-embedded-server

In your Dockerfile, simply COPY the CLI script and RUN it:

FROM quay.io/wildfly/wildfly-centos7

COPY config.cli /opt/wildfly/bin/config.cli

RUN /opt/wildfly/bin/jboss-cli.sh --file="/opt/wildfly/bin/config.cli"

When building the image, you will see that the output (“success”) of the CLI command is echoed on the console:

$ sudo docker build --tag=wildfly-demo .

Step 1/3 : FROM quay.io/wildfly/wildfly-centos7
 ---> f96c9569135d
Step 2/3 : COPY config.cli /opt/wildfly/bin/config.cli
 ---> Using cache
 ---> bec179be034c
Step 3/3 : RUN /opt/wildfly/bin/jboss-cli.sh --file="/opt/wildfly/bin/config.cli"
 ---> Running in bb60b38058bc
  . . . .
{"outcome" => "success"}
 ---> 8f6b2e0c06b7

Now you can run the container with:

$ sudo docker run -it wildfly-demo

If you log into the Container image of WildFly, you will see that the System Property (“foo”) has been added to WildFly configuration.

Found the article helpful? if so please follow us on Socials