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.

    images/01_DockerNewProject.png

  2. When the project is created, add text (e.g. Hello World!) to index.jsp, see e.g. Developing source code.

    images/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.

    images/04_DockerDockerFile.png

    This Dockerfile sets jboss/wildfly as the base image and copies the local file <artifact-name>.war located in the same as the Dockerfile directory to the server deployment directory
    /opt/jboss/wildfly/standalone/
    deployments/.

3. Configure a WAR artifact

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S) and select Artifacts.
  2. Click images/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.

    images/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 images/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: images/runTwoGreenArrows.png | Edit '<ConfigurationName>'.
  2. Select the Container tab, expand the Port bindings section, and click images/add.png to create a new port mapping.

    You can also add the corresponding Build artifact task to the Before launch task list. Then, your WAR artifact will be built automatically each time you execute the run configuration.

  3. In the dialog that opens, specify:
    • Container port: 8080
    • Protocol: tcp
    • Host IP: 0.0.0.0
    • Host port: 18080

    images/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>/

    images/09_DockerAppInBrowser.png

See Also

Languages, Frameworks and Technologies:

Tutorials and Examples: