Showing posts with label Dockerfile. Show all posts
Showing posts with label Dockerfile. Show all posts

Saturday, May 5, 2018

3. Learning How to build Best Docker images?

The containerization concept was available since the 1978s in the UNIX. but the real usage and evaluation started from the year 2014 onward, a small community of docker open-source organizations started to focus on it and developing it.

In the last post, we had the unofficial image then it went up the size up to 3.8 GB. But same logic if we try on Oracle Linux 7-Slim version image it reduced 1 GB!!!

  Use Layered approach for Oracle images  

Most of the developers question how do we deliver it to end-user when you create the containers for WebLogic. The best practice to use the layered approach for WebLogic applications. We have demonstrated with the following layer approach the whole stack is going to break down into two major parts:

  1. Read-only 
  2. Read-write 
The latest image is on top which is only allows you to modify the content. where application jar/war/ear file will be deployed.
The bottom stack will be re-used by multiple developers to build their container and work with no-time spending that's the beauty of this containerization technology.


Please refer to the Oracle White paper.
WebLogic docker image layers


Recently we had a requirement to develop the containers of Oracle SOA. if we take the old stack it is not flexible enough to support the requirements. Always prefer to use the latest installers, Oracle SOA 12c is flexible for supporting Containerization.

Use the yum -y clean

When you install any of the dependent libraries that used for WebLogic or database or SOA software in the container. These libraries first pulled from the repo to a buffer, then installation process happen. Better to clean this junk after installation completed.

Preferable option to use official images
When you search for any image then you will be finding many images which are publicly available. Out of the images list there could be official select that one, which is more reliable than others.

Use Dockerfile to build images

Remember that in Dockerfile every instruction line is going to create a container. Each container will be stored in the docker engine just similar to the SVN repository that have id. To build docker image by writing single RUN command with slash for separating commands for multiple commands to execute on the temporary container.

Use docker-compose instead of lengthy docker run

using docker-compose you will be saving time to write lengthy docker run commands. If you store the run command into composing file you will have more advantages you can build the docker image and also run the image as a container in a single go. You can modify the ports and other values to create more containers.

Multi-purpose of docker-compose commands

Please follow my YouTube Channel. Write your experiences/queries with the docker and docker-compose in the below give comment box. We are happy to help you in containerizing your environments.


References

Oracle WebLogic Server on Docker Containers

Monday, July 24, 2017

2. Writing Dockerfiles to install JDK and WebLogic to create docker images

We have a couple of options to create the docker images. In the last post, we got the docker installed Linux environment available. Now in this post, we will develop the Dockerfile such that it can create an image that can have Java JRE installed and WebLogic 12c installed.

Lets jump on the task where we will prepare, create the Dockerfile and build the image and run the container to check all done successful.

Prepare software installation


Remember that official images always the preferable choice. When you search for docker images from the public repository that is hub.docker.com. We might get a huge list some of them are Automated some of them are not. The only one will be committed as an Official Image. Here selecting an image is also a strategy, logic inside. So carefully proceed further.

We need to install Java Development Kit JDK latest version and WebLogic in silent mode installation.

Step 1: Copy installers to data folder this is my convention I've used
Here few Dockerfile commands

  1. FROM - used to specify the base image
  2. MAINTAINER [depricated]- tell about the author
  3. RUN - executable commands separated by &&
  4. USER - like su command in Linux is used for switch user
  5. ENV - environment variables definitions predefined
  6. ADD - share directories or files
  7. WORKDIR - login is like cd in Linux you perform some of the commands there and then you can use one more time and perform
  8. COPY - copy the files from the host machine to container it is like scp
  9. CMD - Execute command where you can give multiple commands in double quotes
  10. ENTRYPOINT - when the container started immediately this instruction will be executed


Now we are good to go for creating the customized Docker Image using Dockerfile as follows:


# WLS DOCKERFILES PROJECT
# --------------------------
# Pull base image
# ---------------
FROM dnraikes/oraclelinux-7:latest

# Maintainer
# ----------
MAINTAINER Pavan Devarakonda 

RUN mkdir -p /u01 /data && \
    chmod a+xr /u01 && \
    useradd -b /u01 -d /u01/oracle -m -s /bin/bash oracle && \
    chown oracle:oracle -R /u01 && \
    chown oracle:oracle -R /data

USER oracle

ENV PATH=/bin:$PATH

ADD ./data /data
ADD ./silent /u01/silent
ADD  wls_installer.sh /u01/wls_installer.sh

WORKDIR /u01
RUN /u01/wls_installer.sh

I'm just doing this experiment how much size this container would make that really matters.

Step 2: Copy silent folder containing wls_install.rsp, oraInst.loc with appropriate group and inventory location. Ref : Single hit installation of WebLogic 12c on Vagrant box

JDK, WebLogic Installation

Revisiting the last blog post few changes made which will help you to prepare the docker image while it creates the image it will install JDK and WebLogic into the intermediate containers.

#!/bin/bash
# This script will be installing JDK installing WebLogic in silent mode
#
#- Info
#-    Author   : Pavan Devarakonda
#-    Date     : 30-March-2017
##############################################3

JDK_INSTALLER=jdk-8u121-linux-x64.tar.gz
JDK_INSTALLER_PATH=/data
INSTAL_LOC=/u01/oracle

echo "installing JDK ${JDK_INSTALLER}"
cd $INSTAL_LOC
tar -zxvf $JDK_INSTALLER_PATH/$JDK_INSTALLER

ls -l
echo confirm JDK installation
cd $INSTAL_LOC/jdk*

JAVA_HOME=`pwd`
echo "export JAVA_HOME=$JAVA_HOME">>$HOME/.bashrc
echo "export PATH=$JAVA_HOME/bin:$PATH">>$HOME/.bashrc

. $HOME/.bashrc

echo "Check for java version"
java -version

echo Installing WebLogic now...
WLS_INSTALLER=fmw_12.2.1.0.0_wls.jar
WLS_INSTALLER_PATH=/data

SILENT_DIR=/u01/silent

java -jar $WLS_INSTALLER_PATH/$WLS_INSTALLER -silent -invPtrLoc $SILENT_DIR/oraInst.loc -responseFile $SILENT_DIR/wls_install.rsp

echo "WebLogic $WLS_INSTALLER installed successfully...."
echo .
echo setting MW_HOME ...
MW_HOME=`grep ORACLE_HOME $SILENT_DIR/wls_install.rsp |cut -d'=' -f2`
echo "export MW_HOME=$MW_HOME">>$HOME/.bashrc
echo "export WL_HOME=$MW_HOME/wlserver">>$HOME/.bashrc
echo "alias wlst=$MW_HOME/oracle_common/common/bin/wlst.sh">>$HOME/.bashrc
. $HOME/.bashrc

Step 3: Run the docker build as follows:
#!/bin/bash
#

# ################## #
# BUILDING THE IMAGE #
# ################## #
echo "Building image '$IMAGE_NAME' ..."

IMAGE_NAME="wlsimg"
NOCACHE=true

BUILD_START=$(date '+%s')
docker build --force-rm=$NOCACHE --no-cache=$NOCACHE -t $IMAGE_NAME . || {
  echo "There was an error building the image."
  exit 1
}
BUILD_END=$(date '+%s')
BUILD_ELAPSED=`expr $BUILD_END - $BUILD_START`

echo ""

chmod u+x build.sh
./build.sh

After the WebLogic docker image builds completed you can see the following lines at the end:

Successful execution of docker build

The docker image list looks like this, where you can see the build image with the tag mentioned in the above :

WebLogic docker image

Further experimenting on dockerization of WebLogic - Using containers will be posted soon.

Reference:

  1. GitHub link for Oracle-WebLogic docker build

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com
QK7QN6U9ZST6