How to do it...

To build your Java EE container, you'll first need a Docker image. To build it, you'll need a Dockerfile such as this:

FROM openjdk:8-jdk

ENV GLASSFISH_HOME /usr/local/glassfish
ENV PATH ${GLASSFISH_HOME}/bin:$PATH
ENV GLASSFISH_PKG latest-glassfish.zip
ENV GLASSFISH_URL https://download.oracle.com/glassfish/5.0/nightly/latest-glassfish.zip

RUN mkdir -p ${GLASSFISH_HOME}

WORKDIR ${GLASSFISH_HOME}

RUN set -x
&& curl -fSL ${GLASSFISH_URL} -o ${GLASSFISH_PKG}
&& unzip -o $GLASSFISH_PKG
&& rm -f $GLASSFISH_PKG
&& mv glassfish5/* ${GLASSFISH_HOME}
&& rm -Rf glassfish5

RUN addgroup glassfish_grp
&& adduser --system glassfish
&& usermod -G glassfish_grp glassfish
&& chown -R glassfish:glassfish_grp ${GLASSFISH_HOME}
&& chmod -R 777 ${GLASSFISH_HOME}

COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh

USER glassfish

ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 4848 8080 8181
CMD ["asadmin", "start-domain", "-v"]

This image will be our base image from which we will construct other images in this chapter. Now we need to build it:

docker build -t eldermoraes/gf-javaee-jdk8 .

Go ahead and push it to your Docker Registry at Docker Hub:

docker push eldermoraes/gf-javaee-jdk8

Now you can create another image by customizing the previous one, and then put your app on it:

FROM eldermoraes/gf-javaee-jdk8

ENV DEPLOYMENT_DIR ${GLASSFISH_HOME}/glassfish/domains/domain1/autodeploy/

COPY app.war ${DEPLOYMENT_DIR}

In the same folder, we have a Java EE application file (app.war) that will be deployed inside the container. Check the See also section to download all the files.

Once you save your Dockerfile, you can build your image:

docker build -t eldermoraes/gf-javaee-cookbook .

Now you can create the container:

docker run -d --name gf-javaee-cookbook 
-h gf-javaee-cookbook
-p 80:8080
-p 4848:4848
-p 8686:8686
-p 8009:8009
-p 8181:8181
eldermoraes/gf-javaee-cookbook

Wait a few seconds and open this URL in your browser:

http://localhost/app

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.28.70