IntelliJ IDEA 2017.2 Help

Deploying a web app into the Wildfly container

In this example, a one-page JSP application is deployed into a Wildfly app server image-based container.

1. Develop the app

  1. Create a project for developing a Java web application: File | New | Project | Java | Web Application, etc.
    /help/img/idea/2017.2/01_DockerNewProject.png
  2. When the project is created, add text (e.g. Hello World!) to index.jsp, see e.g. Developing source code.
    /help/img/idea/2017.2/02_DockerIndexJsp.png

2. Specify deployment info in a Dockerfile

  1. In the project root directory, create a new directory (e.g. docker-dir): File | New | Directory.

    We'll use this directory to store our Dockerfile and a .war application artifact.

  2. In the docker-dir directory, create a Dockerfile.
  3. Add the following to your Dockerfile:
    FROM jboss/wildfly COPY <artifact-name>.war /opt/jboss/wildfly/standalone/deployments/

    Use the actual artifact name in place of <artifact-name>. On the following picture, the name of the artifact is HelloDocker.

    /help/img/idea/2017.2/04_DockerDockerFile.png

3. Configure a WAR artifact

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S) and select Artifacts.
  2. Click /help/img/idea/2017.2/new.png, select Web Application: Archive and select For '<project-name>:war exploded'.
  3. Change the artifact name. The name should be the same as in your Dockerfile (<artifact-name>) but without .war at the end.
  4. Select the docker-dir directory as the artifact output directory.
    /help/img/idea/2017.2/05_DockerArtifact.png
  5. Click OK in the Project Structure dialog.

4. Build the artifact

  • Select Build | Build Artifacts | <WarArtifactName> | Build.

5. Run your Dockerfile

  • In your Dockerfile, click /help/img/idea/2017.2/runTwoGreenArrows.png and select Run on 'Docker'.

6. Map the container http port 8080 onto a host port

  1. Open the run configuration associated with your Dockerfile for editing: /help/img/idea/2017.2/runTwoGreenArrows.png | Edit '<ConfigurationName>'.
  2. Select the Container tab, expand the Port bindings section, and click /help/img/idea/2017.2/add.png to create a new port mapping.
  3. In the dialog that opens, specify:
    • Container port: 8080
    • Protocol: tcp
    • Host IP: 0.0.0.0
    • Host port: 18080
    /help/img/idea/2017.2/06_DockerRunConfig_Container.png
  4. Click Run.

7. Check the application output in a browser

When the container is started, open a web browser and go to:

  • If you are using Docker for Windows, macOS or Linux: http://localhost:18080/<artifact-name>/
  • If you are using the Docker Toolbox for Windows or macOS (deprecated): http://192.168.99.100:18080/<artifact-name>/
    /help/img/idea/2017.2/09_DockerAppInBrowser.png
Last modified: 11 October 2017

See Also

Languages, Frameworks and Technologies: