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.


Recommended Articles

Manage Docker Images from Eclipse JBoss Tools

Learn how to use Eclipse JBoss tools to manage Docker images and deploy applications on top of them

Run Containers without Docker: Get Started with Podman

Learn how to run Linux containers and deploy WildFly application server using Podman, a container runtime that doesn't require a daemon to run on your system.

Master Dockerfile Syntax and Commands for Efficient Image Building

Learn how to use Dockerfile commands like FROM, ARG, and CMD in this comprehensive tutorial. #Docker #Java #CloudNative

Second Tutorial: Deploy Applications with Docker Files for WildFly

Learn how to deploy applications using Dockerfiles in this second tutorial on running WildFly with Docker. #Docker #WildFly #Java #CloudNative