First lets create Docker image in standard way:
FROM jboss/wildfly
RUN curl -Ls https://github.com/andrzejszywala/hellojee/raw/master/hellojee.war -o /opt/jboss/wildfly/standalone/deployments/hellojee.war
Build image
docker build -t hello_wildfly .
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello_wildfly latest cc8926d06bf0 25 minutes ago 745MB
Now lets use Galeon to create smaller wildfly
# In first stage prepare wildfly
FROM adoptopenjdk/openjdk11:alpine-slim as WILDFLY_BUILD
ENV GALEON_VERSION 3.0.2.Final
RUN apk --update add --no-cache --virtual .build-deps unzip curl bash
RUN curl -Ls https://github.com/wildfly/galleon/releases/download/$GALEON_VERSION/galleon-$GALEON_VERSION.zip -o /tmp/galeon.zip
RUN unzip /tmp/galeon.zip -d /tmp
RUN /tmp/galleon*/bin/galleon.sh install wildfly:current --layers=cdi,jaxrs,jpa,h2-database --dir=/tmp/wildfly
RUN curl -Ls https://github.com/andrzejszywala/hellojee/raw/master/hellojee.war -o /tmp/wildfly/standalone/deployments/hellojee.war
# Second stage builds final image
FROM adoptopenjdk/openjdk11:alpine-slim
ENV LAUNCH_JBOSS_IN_BACKGROUND true
EXPOSE 8080
# Copy wildfly with application from temporary image
COPY --from=WILDFLY_BUILD /tmp/wildfly /opt/wildfy
CMD ["/opt/wildfy/bin/standalone.sh", "-b", "0.0.0.0"]
Build image
docker build -t hello_galeon .
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello_galeon latest a719b9633749 13 minutes ago 365MB
As you can see image is half the size.
No comments:
Post a Comment