Optimized WebLogic Image on Docker

Posted by Dirk Nachbar on Wednesday, May 08, 2019
As I am currently busy with optimizing Docker Images for Oracle stuff, I want to share with you my latest optimization for Oracle WebLogic Server 12.2.1.3.0 as Docker Image.

Under the Oracle GitHub Repository https://github.com/oracle/docker-images/tree/master/OracleWebLogic you can find all necessary files to build a Docker Image for Oracle WebLogic 12.2.1.x, which are quite useful, but the disadvantage of this image is the size. The Docker Image will be 2.93 GB !
So I spent some time and optimized the Docker build and my optimized Docker image is only 1.4 GB, so more than 50% space savings ;-)

 # Docker Images
$ docker images
REPOSITORY           TAG                  IMAGE ID            CREATED             SIZE
oracle/weblogic      12.2.1.3-optimized   854be1c2bbb9        7 minutes ago       1.4GB
oracle/weblogic      12.2.1.3-generic     ba0d1c2dc430        25 minutes ago      2.93GB

The complete showcase you can find under my GitHub Repository https://github.com/DirkNachbar/Docker/tree/master/OracleWebLogic, just clone the Repo and perform following steps.

Download at first following software from Oracle Technology Network:

After the download of the required installation files, build at first the Oracle Server JRE Image

#
$ cd dockerfiles/12.2.1.3/serverjre
$ ./buildDockerImage.sh
$ docker images | grep serverjre
REPOSITORY           TAG                  IMAGE ID            CREATED             SIZE
oracle/serverjre     8                    63b4768f6557        About an hour ago   387MB

As next you can build the Oracle WebLogic Server 12.2.1.3.0 Image

#
cd dockerfiles
$ ./buildDockerImage.sh -v 12.2.1.3 -o

Checking if required packages are present and valid...
fmw_12.2.1.3.0_wls_Disk1_1of1.zip: OK
=====================
Building image 'oracle/weblogic:12.2.1.3-optimized' ...
Sending build context to Docker daemon    839MB
Step 1/17 : FROM oracle/serverjre:8 as base
 ---> 63b4768f6557
Step 2/17 : LABEL maintainer="dirk.nachbar@trivadis.com"
 ---> Running in 9bfcf5aaa1d4
Removing intermediate container 9bfcf5aaa1d4
 ---> 6cff4f8712d8
. . .
. . .
Step 13/17 : FROM base
 ---> 718f0506dfb8
Step 14/17 : COPY --chown=oracle:oracle --from=builder $ORACLE_HOME $ORACLE_HOME
 ---> 46ee0e3fd822
Step 15/17 : COPY --chown=oracle:oracle --from=builder $JAVA_HOME $JAVA_HOME
 ---> bddc30cf710e
Step 16/17 : WORKDIR ${ORACLE_HOME}
 ---> Running in b7a122dc521b
Removing intermediate container b7a122dc521b
 ---> 1b2aa03acef6
Step 17/17 : CMD ["/u01/oracle/createAndStartEmptyDomain.sh"]
 ---> Running in 296506a7fc03
Removing intermediate container 296506a7fc03
 ---> 854be1c2bbb9
Successfully built 854be1c2bbb9
Successfully tagged oracle/weblogic:12.2.1.3-optimized

  WebLogic Docker Image for 'optimized' version 12.2.1.3 is ready to be extended:

    --> oracle/weblogic:12.2.1.3-optimized

  Build completed in 258 seconds.

$ docker images
REPOSITORY           TAG                  IMAGE ID            CREATED             SIZE
oracle/weblogic      12.2.1.3-optimized   854be1c2bbb9        24 minutes ago      1.4GB

Now create and run your Oracle WebLogic Server 12.2.1.3.0 Container:

#
$ docker run -d --name <ContainerName> \
             -p 7001:7001 -p 9002:9002 \
             -v <Host Path to subdirectory properties>:/u01/oracle/properties \
             -e ADMINISTRATION_PORT_ENABLED=true -e DOMAIN_NAME=<DomainName> \
             oracle/weblogic:12.2.1.3-optimized

$ docker logs -f <ContainerName>

# For Example:

$ docker run -d --name wls12213optimized \
             -p 7001:7001 -p 9002:9002 \
             -v /work/OracleWebLogic/dockerfiles/12.2.1.3/properties:/u01/oracle/properties \
             -e ADMINISTRATION_PORT_ENABLED=true -e DOMAIN_NAME=OptimizedDomain \
             oracle/weblogic:12.2.1.3-optimized

$ docker logs -f wls12213optimized
. . .
. . .
<May 8, 2019 8:56:16,862 AM UTC> <Notice> <WebLogicServer> <BEA-000329> <Started the WebLogic Server Administration Server "AdminServer" for domain "OptimizedDomain" running in production mode.> 
<May 8, 2019 8:56:16,864 AM UTC> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[1]" is now listening on 127.0.0.1:7002 for protocols iiops, t3s, ldaps, https.> 
<May 8, 2019 8:56:16,865 AM UTC> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure" is now listening on 172.17.0.2:7002 for protocols iiops, t3s, ldaps, https.> 
<May 8, 2019 8:56:16,865 AM UTC> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 172.17.0.2:7001 for protocols iiop, t3, ldap, snmp, http.> 
<May 8, 2019 8:56:16,866 AM UTC> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.> 
<May 8, 2019 8:56:16,866 AM UTC> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[1]" is now listening on 127.0.0.1:7002 for protocols iiops, t3s, ldaps, https.> 
<May 8, 2019 8:56:16,866 AM UTC> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure" is now listening on 172.17.0.2:7002 for protocols iiops, t3s, ldaps, https.> 
<May 8, 2019 8:56:16,867 AM UTC> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 172.17.0.2:7001 for protocols iiop, t3, ldap, snmp, http.> 
<May 8, 2019 8:56:16,867 AM UTC> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.> 
<May 8, 2019 8:56:16,881 AM UTC> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.> 
<May 8, 2019 8:56:16,911 AM UTC> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.> 

With a little bit work of adding multi stage build in the Dockerfile, you are able to save more than 50% of the space in your Docker Image ;-)