A JBoss Project
Red Hat

Latest posts

If you’ve already gotten started with trying out Docker and JBoss Tools, and want to see what other options are available, this blog post will explain how to run Wildfly in a Docker container and configure it for management tasks and managed deployments.

Customizing your Dockerfile

Since the default jboss/wildfly Docker configuration doesn’t expose the management port by default, we’ll need to customize it, and this means writing your very first Dockerfile. Our goals here are to add a management user to the Dockerfile, and also to expose the management ports when running the container.

First, you’ll want to make a folder on your filesystem that you can play around in. I’ll name mine docker_jbds_wf_mgmt - Inside this folder, we’ll make a new file named Dockerfile and give it the following content:

FROM jboss/wildfly:latest

USER jboss
RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#70365 --silent
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

You can see that we’re extending the original jboss/wildfly container. In the above RUN command, we’re also adding a management user. Feel free to customize the password as you wish.

Exposing actual or sensitive passwords in a publicly accessible Dockerfile is dangerous. Make sure to only use example credentials in publicly available Dockerfiles.

Finally, we’re making sure that when the Docker container runs standalone.sh, it is also making sure to bind the management port to all possible hosts, helping to expose it for use.

Building your new Dockerfile

You can give your new configuration any name you want when building it. I’ll build mine here, and give it the name wildfly-mgmt :

docker build --tag=wildfly-mgmt .

Running your new Dockerfile

To run your new configuration, run the following command, replacing the last parameter with what name you chose when building the Dockerfile.

docker run -it -p 8080:8080 -p 9990:9990  wildfly-mgmt

Note that, unlike the previous post, we do not need to launch with custom volume mappings. All we need is the addition of the management port.

Configuring a Server in JBoss Tools

local fs 0

When creating the server remember to set the host to be dockerhost ( at least on OSX and Windows ) as shown above.

remote mgmt 1

Since we’ve configured the server to be remote, and for communication with the server to be handled over the management port, we mark it as Remote and controlled by Management Operations in the second page of the New Server wizard. We also don’t require a runtime here, though we may need one later when creating a functional web project with classes. For now, we won’t create one. You’ll also note that we have marked that the Server lifecycle is externally managed, which means we won’t be starting or stopping the server via JBoss Tools, since you’ll be controlling that via Docker on your own.

remote mgmt 2

On the next page, you’ll note that our remote runtime details are optional. Since the server is configured only for management operations, we have no real need to know where the filesystem is located or how to access it. We can safely ignore this page and just proceed through it.

Now, your server is created, but we still need to set the management credentials. First, double-click your Server in the Servers View to open the Server Editor. Then, set your credentials as you did in your Dockerfile as shown below. You’ll note that some default values are already there, and so you’ll need to delete them and set your own values.

remote mgmt credentials

Creating Your Web Project

In this example, we can create a very simple web project by browsing to File → New → Dynamic Web Project, Once the web project is created, we can create a simple index.html in the WebContent folder.

Starting the Server

Now that everything’s set up in Eclipse, we can start our Docker container as we mentioned before:

docker run -it -p 8080:8080 -p 9990:9990  wildfly-mgmt

Starting the Server Adapter

In Eclipse, we can now right-click our server, and select Start. This shouldn’t launch any commands, since we marked the server as Externally Managed. The server adapter is configured to check over the management port at dockerhost:9990 to see if the server is up or not, so it should quickly move to a state of [Started, Synchronized].

Deploying the Web Application

We can now right-click on our index.html project, and select Run As → Run On Server and follow the on-screen directions to deploy our web application. We should then notice the Eclipse internal browser pop up and display the content of our index.html files.

Conclusion

In this second example, we’ve seen how to install and configure a Wildfly Docker image customized for management operations in JBoss Tools.

To summarize, here are the steps needed:

  1. Create your own 'Dockerfile` that uses the existing jboss/wildfly configuration, but also adds a management user and starts server with the management port exposed

  2. Start Docker with 8080 and 9990 mapped

  3. Configure the server to run on dockerhost, using Remote management settings and have lifecycle externally managed

As you hopefully noted, this kind of setup is much more straightforward (no messing with paths); unfortunately it does have a downside since all publishes are full publishes over the management API. Because of this, incremental updates will not work in this case.

In a future example, I hope that we’ll see how to create an image customized for SSH access, which will allow starting and stopping the server and support incremental updates.

Rob Stryker

So you’ve heard the buzzwords and all the hype around Docker, but you haven’t had the chance to play around with it yet or see if it fits your needs. You’re already an avid user of JBoss Tools, and are fairly familiar with starting and stopping your local or remote Wildfly installation, and deploying web applications to it.

If this describes you, and you’re interested in trying out Docker, then this blog is targeted to you.

Docker Installation

Docker’s installation method differs based on your platform. You’ll want to review Docker’s Installation guides for your respective platforms.

To make things unified across the various platform, we recommend you go and map dockerhost to the ip of where your docker instance is running.

By default on Linux that will be 127.0.0.1, so you would add the following line to your /etc/hosts file:

127.0.0.1 dockerhost

But on OSX and Windows it will be a unique IP you can get by running boot2docker ip (i.e. 192.168.59.122). In that case the following should be added:

192.168.59.122 dockerhost

From now on you can use dockerhost in all your applications and get to it no matter what OS you are running on.

Running the default wildfly image

Wildfly has published their docker images for public consumption. You can browse them at the docker registry, or go to http://www.jboss.org/docker/ for more information.

These images are JBoss' standard Docker images and they do not expose more features than just the bare minimum for production and reuse. This first blog will show how to use them as-is, but going forward we will show how to configure them to be a bit more useful for development use cases.

To make sure your docker installation has worked, and that Wildfly can start without any errors, you can do the following:

docker run -it -p 8080:8080 jboss/wildfly

This command will run the Docker image for jboss/wildfly in its default state, no customizations and map port 8080 on your dockerhost to 8080 of the running jboss/wildfly container.

Once this is run, the command will not only start up your container, but also launch the server in standalone mode, and connect a terminal to it so you can see the output.

terminal wf docker

You should also now be able to see WildFly default startup page on http://dockerhost:8080.

Assuming you see the console output, and the server runs with no errors and you can access the welcome browser via dockerhost then you’re set up and ready for the next step.

To terminate the container, you can simply press Ctrl+C. If, for some reason, your image has frozen, and Ctrl+C isn’t working, you can also run the following commands to kill it forcefully.

First list running containers:

[root@localhost docker]$ docker ps
CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS              PORTS                    NAMES
f70149043400        jboss/wildfly:latest   "/opt/jboss/wildfly/   58 seconds ago      Up 58 seconds       0.0.0.0:8080->8080/tcp   ecstatic_darwin

Here I only have one container running; you might have more. But to kill any container, you execute docker kill f70149043400, replacing the given hash with your value from CONTAINER ID column.

Externally Managed Local Server With Deployment Folder Mapping

Since the Docker image in this example does not have SSH enabled, and the Wildfly server is not exposing the Management port, we will need to configure JBoss Tools to use custom filesystem deployments. The way to do this is to map in a local folder from our host into our container.

And since we start Wildfly via the Docker image, on the command-line. we’ll want to configure our Server Adapter in JBoss Tools to be an externally managed server, so it will not manage the start nor stop of the server.

Mapping a deployment folder

For this example, we’ll make a temporary directory somewhere on our host, and tell our Docker container to treat that as the standalone/deployments folder inside the container. In this way, changes made to the folder can be visible in both the host and container.

Mapping Folders may cause IO errors for SELinux!* To ensure your container can actually read and write to the folder, you’ll need to run setenforce 0 to disable SELinux, or, alternatively, give Docker the permissions and exceptions in SELinux. See this stackoverflow post for more information.
[root@localhost jbds_wf_external]$  mkdir /home/rob/tmp/dockertest1
[root@localhost jbds_wf_external]$  docker run -it -p 8080:8080 \
-v /home/rob/tmp/dockertest1:/opt/jboss/wildfly/standalone/deployments/:rw  jboss/wildfly

The ':rw' at the end is important, since without it the docker container cannot write to it, only read.

If you were to now place a .war file inside /home/rob/tmp/dockertest1, it will be picked up by the deployment scanner, and visible in a web browser. Take note of the folder, since we’ll use that in the configuration of the Server Adapter.

Making your Server Adapter

The final step of this example is to create your Wildfly 8.2 server adapter in JBoss Tools, and to create and deploy a web application to your temporary folder, which in my case is /home/rob/tmp/dockertest1

First, we’ll open the Servers View and create a new Wildfly 8.x server adapter. Since we’re exposing our container’s ports on dockerhost, we need to set the host to dockerhost.

local fs 0

The server should still be marked as Local and Controlled by Filesystem and shell operations as shown below.

local fs 1

Since we’re hacking a Local Filesystem server adapter to work for Docker, we’ll still need a local runtime in this example, so point it to any locally installed WildFly server you have.

In JBIDE-19388 we are looking at ways to avoid requiring this step.

Configuring your Server Adapter

Once your server is created, you’ll find it in the Servers View, where we can double-click it to open the Server Editor. From here, we can make what configuration changes we’ll need. First, we’ll need to make sure the server is Externally Managed. This means JBoss Tools will not attempt to start and stop it from Eclipse, it is expecting you the user handles that via Docker.

local fs externally managed

Next, we’ll need to disable the tooling for keeping deployment scanners in sync with the locations JBoss Tools expects to be deploying. Since we’ve already mapped the folder in via the Docker command line, we won’t need any additions to the deployment scanners at all.

local fs scanners

And finally, on the Deployment tab of the Server Editor, we’ll want to mark the default deploy folder to be a Custom location, and choose the folder that we previously mapped in via Docker’s command line, as shown below:

local fs deploy

Once all this is done, we can save the editor, and our server adapter is configured properly.

Make a Web Project

In this example, we can create a very simple web project by browsing to File → New → Dynamic Web Project, Once the web project is created, we can create a simple index.html in the WebContent folder.

Starting the Server

Now that everything’s set up in Eclipse, we can start our Docker container as we mentioned before:

docker run -it -p 8080:8080 -v /home/rob/tmp/dockertest1:/opt/jboss/wildfly/standalone/deployments/:rw  jboss/wildfly

Starting the Server Adapter

In Eclipse, we can now right-click our server, and select Start. This shouldn’t launch any commands, since we marked the server as Externally Managed. The server adapter is configured to check dockerhost:8080 to see if the server is up or not, so it should quickly move to a state of [Started, Synchronized].

Deploying the Web Application

We can now right-click on our index.html project, and select Run As → Run On Server and follow the on-screen directions to deploy our web application. We should then notice the Eclipse internal browser pop up and display the content of our index.html files.

Congratulations - you just used JBoss Tools to deploy a local running Docker hosted WildFly server.

What could be better ?

The default docker image is restricted by default. This means it does not have the Management port exposed, nor JMX nor file system access via SSH.

All this means that currently you have to go through some setup to use them from existing tools, but luckily we are doing two things:

  1. we will post more blogs explaning how to enable some of these features to use todays tools (not just JBoss Tools) with 'raw' docker.

  2. we are working on making the steps simpler when using Docker 'raw'

Conclusion

In this first example, we’ve seen how to install and configure the default Wildfly Docker images.

To summarize, here are the steps needed:

  1. Start Docker with 8080 mapped and with /opt/jboss/wildfly/standalone/deployments mounted as volume

  2. Configure server to run on dockerhost, be externally managed and Custom deploy to the volume above

In future examples, we’ll see how to extend those images for Management or SSH/SCP usecases.

Rob Stryker

JBoss Tools 4.29.1.Final for Eclipse 2023-09

by Stéphane Bouchet on Jun 13, 2024.

JBoss Tools 4.29.0.Final for Eclipse 2023-09

by Stéphane Bouchet on Nov 02, 2023.

JBoss Tools 4.28.0.Final for Eclipse 2023-06

by Stéphane Bouchet on Jul 03, 2023.

JBoss Tools for Eclipse 2023-06M2

by Stéphane Bouchet on Jun 05, 2023.

JBoss Tools 4.27.0.Final for Eclipse 2023-03

by Stéphane Bouchet on Apr 07, 2023.

Looking for older posts ? See the Archived entries.
back to top