Skip to content

Latest commit

 

History

History
219 lines (172 loc) · 8.12 KB

docker-deployment-options.adoc

File metadata and controls

219 lines (172 loc) · 8.12 KB

Build and Deploy Java EE 7 Application

Java EE 7 Simple Sample is a trivial Java EE 7 sample application.

Build Application

  1. Clone the repo:

    git clone https://github.com/javaee-samples/javaee7-simple-sample.git
  2. Build the application:

    mvn clean package

Start Application Server

Start WildFly server as:

docker run --name wildfly -d -p 8080:8080 -v /Users/youruser/javaee7-simple-sample/target:/opt/jboss/wildfly/standalone/deployments/:rw jboss/wildfly

Make sure to replace /Users/youruser/javaee7-simple-sample/target to the target directory of your checked out project.

This command starts a container named “wildfly”.

The -v flag maps a directory from the host into the container. This will be the directory to put the deployments. rw ensures that the Docker container can write to it.

Warning
Windows users, please make sure to use -v /c/Users/ notation for drive letters.

Check logs to verify if the server has started.

docker logs -f wildfly

Access http://dockerhost:8080 in your browser to make sure the instance is up and running.

Now you’re ready to deploy the application for the first time.

Configure JBoss Developer Studio

Start JBoss Developer Studio, if not already started.

  1. Select ‘Servers’ tab, create a new server adapter

    jbds1
    Figure 1. Server adapter
  2. Assign an existing or create a new WildFly 9.0.0 runtime (changed properties are highlighted.)

    jbds2
    Figure 2. WildFly Runtime Properties
  3. If a new runtime needs to be created, pick the directory for WildFly 9.0.0:

    jbds3
    Figure 3. WildFly 9.0.0.Final Runtime

    Click on ‘Finish’.

  4. Double-click on the newly selected server to configure server properties:

    jbds4
    Figure 4. Server properties

    The host name is specified to ‘dockerhost’. Two properties on the left are automatically propagated from the previous dialog. Additional two properties on the right side are required to disable to keep deployment scanners in sync with the server.

  5. Specify a custom deployment folder on Deployment tab of Server Editor

    jbds5
    Figure 5. Custom deployment folder
  6. Right-click on the newly created server adapter and click ‘Start’.

    jbds6
    Figure 6. Started server

Deploy Application Using Shared Volumes

  1. Import javaee7-simple-sample application source code using Import → Existing Maven Projects.

  2. Right-click on the project, select ‘Run on Server’ and chose the previously created server.

The project runs and displays the start page of the application.

jbds7
Figure 7. Start Server

Congratulations!

You’ve deployed your first application to WildFly running in a Docker container from JBoss Developer Studio.

Stop WildFly container when you’re done.

docker stop wildfly

Deploy Application Using CLI

The Command Line Interface (CLI) is a tool for connecting to WildFly instances to manage all tasks from command line environment. Some of the tasks that you can do using the CLI are:

  1. Deploy/Undeploy web application in standalone/Domain Mode.

  2. View all information about the deployed application on runtime.

  3. Start/Stop/Restart Nodes in respective mode i.e. Standalone/Domain.

  4. Adding/Deleting resource or subsystems to servers.

Lets use the CLI to deploy javaee7-simple-sample to WildFly running in the container.

  1. CLI needs to be locally installed and comes as part of WildFly. This should be available in the previously downloaded WildFly. Unzip into a folder of your choice (e.g. /Users/arungupta/tools/). This will create wildfly-9.0.0.Final directory here. This folder is referred to $WIDLFY_HOME from here on. Make sure to add the /Users/arungupta/tools/wildfly-9.0.0.Final/bin to your $PATH.

  2. Run the “wildfly-management” image with fixed port mapping as explained in [Management_Fixed_Port_Mapping].

  3. Run the jboss-cli command and connect to the WildFly instance.

    jboss-cli.sh --controller=dockerhost:9990  -u=admin -p=docker#admin -c

    This will show the output as:

    [standalone@dockerhost:9990 /]
  4. Deploy the application as:

    deploy <javaee7-simple-sample PATH>target/javaee7-simple-sample-1.10.war --force

Now you’ve sucessfully used the CLI to remote deploy the Java EE 7 sample application to WildFly running as docker container.

Deploy Application Using Web Console

WildFly comes with a web-based administration console. It also relies on the same management APIs that are used by JBoss Developer Tools and the CLI. It provides a simple and easy to use web-based console to manage WildFly instance. For a Docker image, it needs to be explicitly enabled as explained in [Enabling_WildFly_Administration]. Once enabled, it can be accessed at http://dockerhost:9990.

console1
Figure 8. WildFly Web Console

Username and password credentials are shown in [WildFly_Administration_Credentials].

Note

You may like to stop and remove the Docker container running WildFly. This can be done as docker ps -a | grep wildfly | awk '{print $1}' | xargs docker rm -f.

Start a new container as docker run -d --name wildfly -p 8080:8080 -p 9990:9990 arungupta/wildfly-management.

Deploy the application using the console with the following steps:

  1. Go to ‘Deployments’ tab.

    wildfly9 deployments tab
    Figure 9. Deployments tab in WildFly Web Console
  2. Click on ‘Add’ button.

  3. On ‘Add Deployment’ screen, take the default of ‘Upload a new deployment’ and click ‘Next>>’.

  4. Click on ‘Choose File’, select <javaee7-simple-sample PATH>/javaee7-simple-sample.war file on your computer. This would be javaee7-simple-sample/target/javaee7-simple-sample.war from Build Application.

  5. Click on ‘Next>>’.

  6. Select ‘Enable’ checkbox.

    wildfly9 add deployments
    Figure 10. Enable a deployment
  7. Click ‘Finish’.

    wildfly9 javaee7 simple sample deployed
    Figure 11. Java EE 7 Simple Sample Deployed

This will complete the deployment of the Java EE 7 application using Web Console. The output can be seen out http://dockerhost:8080/javaee7-simple-sample and looks like:

wildfly9 javaee7 simple sample output
Figure 12. Java EE 7 Simple Sample Output

Deploy Application Using Management API

A standalone WildFly process, process can be configured to listen for remote management requests using its “native management interface”. The CLI tool that comes with the application server uses this interface, and user can develop custom clients that use it as well. By default, WildFly management interface listens on 127.0.0.1. When running inside a Docker container, the network interface should be bound to all publicly assigned addresses. This can be easily changed by biding to 0.0.0.0 instead of 127.0.0.1.

  1. Start another WildFly instance again:

    docker run -d --name wildfly -p 8080:8080 -p 9990:9990 arungupta/wildfly-management

    In addition to application port 8080, the administration port 9990 is exposed as well. The WildFly image that is used has tweaked the start script such that the management interface is bound to 0.0.0.0.

  2. Create a new server adapter in JBoss Developer Studio and name it “WildFly 9.0.0-Management”. Specify the host name as ‘dockerhost’.

    jbds8
  3. Click on ‘Next>’ and change the values as shown.

    jbds9
    Figure 13. Create New Server Adapter
  4. Take the default values in ‘Remote System Integration’ and click on ‘Finish’.

  5. Change server properties by double clicking on the newly created server adapter. Specify admin credentials (username: docker, password: docker#admin). Note, you need to delete the existing password and use this instead:

    jbds10
    Figure 14. Management Login Credentials
  6. Right-click on the newly created server adapter and click ‘Start’. Status quickly changes to ‘Started’ as shown.

    jbds11
    Figure 15. Synchronized WildFly Server
  7. Right-click on the javaee7-simple-sample project, select ‘Run on Server’ and choose this server. The project runs and displays the start page of the application.

  8. Stop WildFly when you’re done.

    docker stop wildfly