I am trying to deploy my Java EE application using a Glassfish 4.1 server and I would like to deploy it as a Docker container.
I'd like writing the correct Docker command to download/start a Glassfish server and then deploy my application on it, using the corresponding GIT repository.
Currently I am able to build a Docker container starting a Glassfish server with the following Dockerfile:
FROM java:8-jdk
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV GLASSFISH_HOME /usr/local/glassfish4
ENV PATH $PATH:$JAVA_HOME/bin:$GLASSFISH_HOME/bin
RUN apt-get update && \
apt-get install -y curl unzip zip inotify-tools && \
rm -rf /var/lib/apt/lists/
RUN curl -L -o /tmp/glassfish-4.1.zip http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip && \
unzip /tmp/glassfish-4.1.zip -d /usr/local && \
rm -f /tmp/glassfish-4.1.zip
EXPOSE 8080 4848 8181
WORKDIR /usr/local/glassfish4
# verbose causes the process to remain in the foreground so that docker can track it
CMD asadmin start-domain --verbose
Then, I build the Docker container (named 'myglassfish')
docker build -t myglassfish .
Finally, I launch the glassfish on my port 8080 using the following command line:
docker run -d -ti -p 4848:4848 -p 8080:8080 myglassfish
The glassfish server is correctly started because I can see the following information by taping 'localhost:8080' on my browser :
'Your server is now running...' (I cannot display the screenshot)
Now, I would like deploying my web application on that server, ideally using the GIT repository of my project (prefered solution) or a war file export of the application.
Let's take the simplest example, supposing I want to deploy my war named myapp.war (in the path /path1/path2/myapp.war) on my server. Is the next dockerfile correct (just add 'CMD asadmin deploy...' at the end of the dockerfile)?
FROM java:8-jdk
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV GLASSFISH_HOME /usr/local/glassfish4
ENV PATH $PATH:$JAVA_HOME/bin:$GLASSFISH_HOME/bin
RUN apt-get update && \
apt-get install -y curl unzip zip inotify-tools && \
rm -rf /var/lib/apt/lists/*
RUN curl -L -o /tmp/glassfish-4.1.zip http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip && \
unzip /tmp/glassfish-4.1.zip -d /usr/local && \
rm -f /tmp/glassfish-4.1.zip
EXPOSE 8080 4848 8181
WORKDIR /usr/local/glassfish4
# verbose causes the process to remain in the foreground so that docker can track it
CMD asadmin start-domain --verbose
CMD asadmin deploy /path1/path2/myapp.war
If not, how should I modify the previous Dockerfile to load and deploy my application in the Glassfish server before starting it (I specify that I am a noob in linux and command line instructions so please be explicit in your answers)?
EDIT
I am now able to deploy my war file from my GIT repository using the following Dockerfile:
FROM java:8-jdk
MAINTAINER firstname name <firstname.name@domain.com>
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV GLASSFISH_HOME /usr/local/glassfish4
ENV PATH $PATH:$JAVA_HOME/bin:$GLASSFISH_HOME/bin
RUN apt-get update && \
apt-get install -y curl unzip zip inotify-tools && \
rm -rf /var/lib/apt/lists/
#download and install the glassfish server
RUN curl -L -o /tmp/glassfish-4.1.zip http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip && \
unzip /tmp/glassfish-4.1.zip -d /usr/local && \
rm -f /tmp/glassfish-4.1.zip
#clone and deploy the project on the glassfish server
RUN git clone http://myrepository.git /usr/local/mypath
RUN cp /usr/local/mypath/MyProject/MyProject.war /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/MyProject.war
EXPOSE 8080 4848 8181
WORKDIR /usr/local/glassfish4
# verbose causes the process to remain in the foreground so that docker can track it
CMD asadmin start-domain --verbose
This works perfectly (using docker build and docker run) but I would like to dynamically create my war file rather than directly copy an existing war file in my repository.
I tried the command line 'jar -cvf' to create the war archive from the repository but the directory 'classes' containing all the compiled java classes .class is missing in the war. As a consequence, the war file generated cannot be deployed. As the compiled class .class are not present in my GIT repository, how can I get them (I tried the command 'javac' but the majority of the classes does not define a main method)? Concretely, I just need to adding all compilated class .class in a directory 'classes' in my WAR. Should I use a Maven repository for this?
Thanks by advance!