WebLogic on Docker Containers Series, Part 3 — Creating a Domain Image
In this post, you will learn how to create a WebLogic Domain Image for Docker Containers. Read on and see how it's done.
Join the DZone community and get the full member experience.Join For Free
You already know how to quickly get started with WebLogic on Docker. You also learned with more details how to build an installation Docker image of WebLogic and Oracle JDK. This time, you will learn how to create a WebLogic Domain Image for Docker Containers.
We are pushing some interesting samples of Docker images on GitHub so this way WebLogic customers and users can have a good idea of what is possible (although not everything in there may be officially supported as of this moment, like multihost), but to experiment and learn more about Docker itself. This blog post focuses on the 1221-domain sample, but make sure to subscribe to this blog or follow me on Twitter for future posts that will look into the other samples.
I will also assume that you have the docker-images repository checked out and updated in your computer (with commit 4c36ef9f99c98), and, of course you have Docker installed and properly working. Now moving on.
WebLogic uses a Domain concept for its infrastructure. This is the first thing a developer or administrator must create in order to be able to run a WebLogic Server. There are many ways to create a WebLogic Server Domain: using the Configuration Wizard, using WLST, or even bootstrapping the weblogic.Server class. Since we are using Docker and we want to automate everything, we create the domain with WLST.
TL;DR; Building the Domain Image in 1221-domain Sample
First things first, make sure you have image oracle/weblogic:12.2.1-developer already created. If not, check Part 2 of this series to learn how.
Now, go into folder samples/1221-domain and run the following command:
$ pwd ~/docker-images/OracleWebLogic/samples/1221-domain $ docker build -t 1221-domain --build-arg ADMIN_PASSWORD=welcome1 . [...] $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE 1221-domain latest 327a95a2fbc8 2 days ago 1.195 GB oracle/weblogic 12.2.1-developer b793273b4c9b 2 days ago 1.194 GB oraclelinux latest 4d457431af34 10 weeks ago 205.9 MB
This is what you will end up having in your environment.
Understanding the Sample WLST Domain Creation Script
Customers and users are always welcome to come up with their own scripts and automation process to create WebLogic domains (either for Docker or not), but we shared some examples here to make things easier for them.
The 1221-domain sample has a subfolder named container-scripts that holds a set of handy scripts to create and run a domain image. The most important script though is the create-wls-domain.py WLST script. This file is executed when docker build is called, as you can see in the Dockerfile. In this sample, you learn how to read variables in create-wls-domain.py script with default values, that may be defined in the Dockerfile.
The script defined in this sample requires a set of information in order to create a domain. Mainly, you need to provide:
- Domain name: by default 'base_domain'
- Admin port (although WLS has 7001 by default when installed, this script defaults to 8001 if nothing is provided)
- Admin password: no default. Must inform during build with --build-arg ADMIN_PASSWORD=<your password>
- Cluster Name: defaults to 'DockerCluster'
Note About Clustering
This sample shows how to define a cluster named with whatever is in $CLUSTER_NAME (defaults to DockerCluster) to demonstrate scalability of WebLogic on Docker containers. You can see how the Cluster is created in the WLST file.
Back to the Domain Creation
How to read variables in WLST with default values? Pretty simple:
domain_name = os.environ.get("DOMAIN_NAME", "base_domain") admin_port = int(os.environ.get("ADMIN_PORT", "8001")) admin_pass = os.environ.get("ADMIN_PASSWORD") cluster_name = os.environ.get("CLUSTER_NAME", "DockerCluster")
These variables can be defined as part of your Dockerfile, or even passed as arguments during the build if you are using Docker 1.10 with the new ARG command, as the ADMIN_PASSWORD example shows.
ARG ADMIN_PASSWORD ENV DOMAIN_NAME="base_domain" \ ADMIN_PORT="8001" \ ADMIN_HOST="wlsadmin" \ NM_PORT="5556" \ MS_PORT="7001" \ CLUSTER_NAME="DockerCluster" \
Other variables are defined here (NM_PORT, MS_PORT, ADMIN_HOST), but I'll explain them later on in a future post. Meanwhile, let's continue.
For the next step as part of a domain image creation, you may want to reuse some Domain Template. In the sample script, we used the default template for new domains wlst.jar, but again, if you are working on your own set of domains, feel free to use any template you may already have.
Next, we tell WLST to configure the AdminServer to listen on all addresses that will be available (in the container), and to listen on port as in $ADMIN_PORT.
The 'weblogic' admin user needs a password that you had to provide with --build-arg (or defined directly inside Dockerfile) in $ADMIN_PASSWORD, and then we set that in the script.
For the sake of providing some examples, we also define a JMS Server in the script, but we only target it to the AdminServer. If you want to target to the Cluster, you will have to tweak your own script.
The script is configured to set this domain in Production Mode too.
We set some Node Manager options since we will be using NM as Per Domain (see docs for more details). Remember that each instance of this image (a container) has the same "filesystem", so it is as if you had copied the domain to different servers. If you are an experienced WebLogic administrator, you will quickly understand. If not, please comment and I'll share some links. This is important to be able to run Managed Servers inside containers based on this image. I'll get back to this in the future on running a Clustered WebLogic environment on Docker containers.
There are a couple of other things we could've done in this script, such as:
- Create and define a Data Source
- Create, define, and deploy applications (this is demonstrated as part of the 1221-appdeploy sample)
- And, anything else you can do with WLST in Offline mode (remember that domain does not exist and thus is not running)
But, surely you will quickly find out how to do these for your own domains.
Now that you have a domain Docker image 1221-domain, you are able to start it with:
$ docker run -ti 1221-domain
Now have some fun with tweaking your own WLST scripts for domain creation in Docker.
Published at DZone with permission of Bruno Borges. See the original article here.
Opinions expressed by DZone contributors are their own.