java ee - Content of a dockerfile to run glassfish server and deploy specific application from a git repository -
i trying deploy java ee application using glassfish 4.1 server , deploy docker container.
as consequence, i'd writing correct docker download/start glassfish server , deploy application on it, using corresponding git repository.
currently able build docker container starting glassfish server 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 process remain in foreground docker can track cmd asadmin start-domain --verbose
then, build docker container (named 'myglassfish')
docker build -t myglassfish .
finally, launch glassfish on port 8080 using following command line:
docker run -d -ti -p 4848:4848 -p 8080:8080 myglassfish
the glassfish server correctly started because can see following information taping 'localhost:8080' on browser :
'your server running...' (i cannot display screenshot)
now, deploying web application on server, ideally using git repository of project (prefered solution) or war file export of application.
let's take simplest example, supposing want deploy war named myapp.war (in path /path1/path2/myapp.war) on server. next dockerfile correct (just add 'cmd asadmin deploy...' @ end of 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 process remain in foreground docker can track cmd asadmin start-domain --verbose cmd asadmin deploy /path1/path2/myapp.war
if not, how should modify previous dockerfile load , deploy application in glassfish server before starting (i specify noob in linux , command line instructions please explicit in answers)?
edit
i able deploy war file git repository using 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 , install 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 , deploy project on 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 process remain in foreground docker can track cmd asadmin start-domain --verbose
this works (using docker build , docker run) dynamically create war file rather directly copy existing war file in repository.
i tried command line 'jar -cvf' create war archive repository directory 'classes' containing compiled java classes .class missing in war. consequence, war file generated cannot deployed. compiled class .class not present in git repository, how can them (i tried command 'javac' majority of classes not define main method)? concretely, need adding compilated class .class in directory 'classes' in war. should use maven repository this?
thanks advance!
the best approach (in opinion) create new image extends 'myglassfish' image , includes war file. image have tag matches application's release version. hope war file has been released maven repository, can download during image build. in case war file in local filesystem, copy image. 1 last thing, in case having trouble sharing files machine , boot2docker vm, boot2docker automatically shares users folder in vm. hope helpful. in case have more questions, shoot.
Comments
Post a Comment