Application server in Docker - war deployment with IntelliJ

后端 未结 1 1196
忘了有多久
忘了有多久 2021-01-07 10:20

Hello dear programmers,

I\'m looking into setting up my development with docker containers since I\'m currently working on windows, my setup is now as follows:

相关标签:
1条回答
  • 2021-01-07 10:56

    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.

    0 讨论(0)
提交回复
热议问题