IntelliJ IDEA 2017.3 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 Enterprise | Web Application, etc.
    01 DockerNewProject
  2. When the project is created, add text (e.g. Hello World!) to index.jsp, see e.g. Developing source code.
    02 DockerIndexJsp

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.

    04 DockerDockerFile

3. Configure a WAR artifact

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S) and select Artifacts.
  2. Click new, 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.
    05 DockerArtifact
  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 runTwoGreenArrows 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: runTwoGreenArrows | Edit '<ConfigurationName>'.
  2. Select the Container tab, expand the Port bindings section, and click add 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
    06 DockerRunConfig Container
  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>/
    09 DockerAppInBrowser
Last modified: 12 December 2017

See Also

Languages, Frameworks and Technologies: