How to do it...

To build your Jakarta EE container, you'll need a Docker image. Let's learn how to build one:

  1. You'll need a Dockerfile such as the following one to build a Docker image:
FROM openjdk:8-jdk

ENV GLASSFISH_HOME /usr/local/glassfish
ENV PATH ${GLASSFISH_HOME}/bin:$PATH
ENV GLASSFISH_PKG glassfish-5.1.0.zip
ENV GLASSFISH_URL https://www.eclipse.org/downloads/download.php?file=/glassfish/glassfish-5.1.0.zip&r=1

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"]
  1. This image will be our base image. We will use it to construct other images in this chapter. Now, we need to build it:
docker build -t eldermoraes/gf-jakartaee-jdk8 .
  1. Now, you need to log into your Docker Hub account:
docker login
  1. Go ahead and push it to your Docker registry at Docker Hub:
docker push eldermoraes/gf-jakartaee-jdk8
  1. Now, you can create another image by customizing the preceding one, and then put your app on it:
FROM eldermoraes/gf-jakartaee-jdk8

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

COPY app.war ${DEPLOYMENT_DIR}
  1. In the same folder, we have a Jakarta EE application file (app.war) that will be deployed inside the container. Check the See also section to download all the files.
  2. Once you've save your Dockerfile, you can build your image:
docker build -t eldermoraes/gf-jakartaee-cookbook .
  1. You can push this new image to Docker Hub for later use:
docker login
docker push eldermoraes/gf-jakartaee-cookbook
  1. Now, you can create the container:
docker run -d --name gf-jakartaee-cookbook \
-h gf-jakartaee-cookbook \
-p 80:8080 \
-p 4848:4848 \
-p 8686:8686 \
-p 8009:8009 \
-p 8181:8181 \
eldermoraes/gf-jakartaee-cookbook
  1. Wait a few seconds and open the following URL in your browser:
http://localhost/app