Application server in Docker - war deployment with IntelliJ

前提是你 提交于 2019-12-01 01:07:06

Here is how I have solved the issue you are rising:

  • Assuming you are using Intellij Docker plugin - it is supported since Intellij 14.1
  • I am using maven to copy the war to the a directory named docker located under my project web-app.
  • The docker directory contains the Dockerfile for building the Docker image
  • In the Docker file I copy the packaged war file to the docker image, create a management user to access the administration console on port 9990 and load JBoss

  • Dockerfile content:

    
    FROM jboss/wildfly
    MAINTAINER e.dahari@company.com
    ADD your-awesome-app.war /opt/jboss/wildfly/standalone/deployments/
    RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#70365 --silent
    CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
  • Now you need to create a settings file container_settings.json. This file contains the parameters to run the Docker image you have built:

    
    {
        "_comment" : "My service",
        "Image": "your-awesome-app-name",
        "HostConfig": {
            "PortBindings":{
                "9990/tcp": [{ "HostIp": "0.0.0.0", "HostPort": "9990" }]
        },
        "RestartPolicy": { "Name": "on-failure", "MaximumRetryCount": 5 }
    }
  • Open Intellij Run/Debug Configurations and add a new Docker Deployment as described here
  • The path to container_settings.json should be placed at Container settings field in the UI
  • Once you have finished. You may run the configuration and it will build your Docker container with the new your-awesome-app.war you have just built.

Please note that after building your Docker image for the first time, successive configuration runs are much faster since Docker caches image changes.
Since the only change in your Docker image is the war file, the next configuration runs will only transfer this part of the image.

In general it is important to put the most changing component last in the Docker file as each action in the Docker file is cached.

Hope I have managed to help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!