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
- Create a project for developing a Java web application: , etc.
- When the project is created, add text (e.g.
Hello World!
) toindex.jsp
, see e.g. Developing source code.
2. Specify deployment info in a Dockerfile
- In the project root directory, create a new directory (e.g.
docker-dir
): .We'll use this directory to store our
Dockerfile
and a.war
application artifact. - In the
docker-dir
directory, create aDockerfile
. - 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 isHelloDocker
.
3. Configure a WAR artifact
- Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S) and select Artifacts.
- Click , select Web Application: Archive and select For '<project-name>:war exploded'.
- Change the artifact name. The name should be the same as in your
Dockerfile
(<artifact-name>
) but without.war
at the end. - Select the
docker-dir
directory as the artifact output directory. - Click OK in the Project Structure dialog.
4. Build the artifact
- Select .
5. Run your Dockerfile
- In your
Dockerfile
, click and select Run on 'Docker'.
6. Map the container http port 8080 onto a host port
- Open the run configuration associated with your
Dockerfile
for editing: . - Select the Container tab, expand the Port bindings section, and click to create a new port mapping.
- In the dialog that opens, specify:
- Container port:
8080
- Protocol:
tcp
- Host IP:
0.0.0.0
- Host port:
18080
- Container port:
- 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>/
Last modified: 29 November 2017