问题
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:
A docker image including a jboss which is started and already running
An hg repo checked out on my windows file system which is imported into IntelliJ
A shared folder which is mapped to the deploymentfolder in the docker image
Whenever I want to deploy my war, I'll let IntelliJ build the artifact as an exploded war with output directory to $THE_SHARED_FODLER/mywar.war. Then I'll touch a file in the same repo with mywar.war.deploy. Since this is shared to the deploymentfolder of the jboss docker image, the launched Jboss now deploys my war.
However, since all IntelliJ know is that I've built an artifact to a file-system, I can't get any of the nice support that I would get if I'd deployed the war in a normal way (e.g. having a local jboss and a jboss-run-configuration that deployed the exploded artifact). The frontend stuff (html/css) can always be solved with grunt or similar, but when it comes to the jar-libs the best solution I've come up with so far is to:
rebuild the jar with maven and copy that to the $THE_SHARED_FOLDER/mywar.war/web-inf/lib/
touch a file mywar.war.redeploy
However this makes the turn-around-time from code change to result about 30 secs o here comes a pretty open question: What is a good way to develop towards an application server that is run in a docker image? How do you do today? Have you tried something similar and decided that docker containers is not the way to go for this?
Any input on the subject is highly welcome :-)
Brgrgs stevie the TV
回答1:
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
mavento copy the war to the a directory nameddockerlocated under my project web-app. - The
dockerdirectory contains theDockerfilefor 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
9990and load JBossDockerfile 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 Configurationsand add a newDocker Deploymentas described here - The path to
container_settings.jsonshould be placed atContainer settingsfield 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.
来源:https://stackoverflow.com/questions/32896899/application-server-in-docker-war-deployment-with-intellij