Creating a docker image for WSO2 Complex Event Processor
Introduction While working on a project for one of our customers I had to perform some testing that involved one of the WSO2 product family members, namely the Complex Event […]
Audit and Consulting of Information Systems and Business Processes
Introduction While working on a project for one of our customers I had to perform some testing that involved one of the WSO2 product family members, namely the Complex Event […]
While working on a project for one of our customers I had to perform some testing that involved one of the WSO2 product family members, namely the Complex Event Processor (or CEP for short). While I already tested some of their products a while ago, I always did that on a Windows platform (for ease and personal preferences). But this time I had to integrate it with Graylog2 which was better run on a Linux environment anyway – and this came nicely packaged via a docker image! So I spinned up a shiny new CentOS 7 installation where running graylog was just a yum install -y docker
and docker pull graylog2/allinone
away … For WSO2 CEP installation things looked worse; the publisher only provided a ZIP download which I would have to extract to run the product. So I thought I’d go the extra mile and create a Dockerfile
so I could run both applications nicely in parallel.
As I have never used docker before, I went quickly through their Tutorial and User Guide and gave it a try:
docker pull centos
and interactively running it docker run -i centos /bin/bash
in order to test my modifications.
While I could download the required Oracle JDK or JRE 1.7 automatically, downloading the actual CEP product from WSO2 was not possible without interactively submitting some personal information before being redirected to the actual download link. So had to manually download it in advance and placed the ZIP into a subdirectory src
(below the Dockerfile
).
wget
(with the header option --header "Cookie: oraclelicense=accept-securebackup-cookie"
to suppress the EULA confirmation dialogue) and extracted into /opt/jre-7-linux-x64
with a link to /opt/java
. Export of JAVA_HOME
and expansion of PATH
was done in the recommended way via ENV
(and interactively via export
to be able to test the installation right away).
As mentioned before downloading the actual CEP product was quite difficult to download automatically so I added it into the build process via the COPY src/wso2cep-3.1.0.zip /opt/src/wso2cep-3.1.0.zip
command.
After unzipping it via unzip -q /opt/src/wso2cep-3.1.0.zip -d /opt
the only thing left was to test the installation by running /opt/wso2cep-3.1.0/bin/wso2server.sh
(which would later become the CMD
of the Dockerfile).
I then committed the changes to an intermediate image via docker commit abcd wso2cep-3.1.0
so I could test them prior to build. This step is optional. You can also just build the image and test it directly.
The actual Dockerfile for the build process was the only very short, consisting only of a few commands (mainly specifying the base image and setting the startup command): docker build -t wso2cep-3.1.0 .
# Dockerfile to build WSO2 Complex Event Processor # # Copyright 2014 Ronald Rink, d-fens GmbH # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Build the container # cd <path to Dockerfile> # sudo docker build -t wso2cep-3.1.0 . # # Run a container using the built image # sudo docker run -d -i -p 9443:9443 -t --name cep wso2cep-3.1.0 # # Login to the running container # sudo docker attach cep # # Exit from a attached container # ^p^q (Ctrl+p and Ctrl+q) # # Use CentOS base image FROM centos # Maintainer MAINTAINER Ronald Rink <ronald.rink@d-fens.net> # Update system RUN yum update -y RUN yum install -y wget RUN yum install -y unzip RUN yum install -y tar ## Download and install Oracle JAVA JRE 1.7 RUN cd /opt && wget -q --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7/jre-7-linux-x64.tar.gz RUN cd /opt && tar -zxvf /opt/jre-7-linux-x64.tar.gz RUN rm /opt/jre-7-linux-x64.tar.gz RUN ln -s /opt/jre1.7.0 /opt/java ENV JAVA_HOME /opt/java ENV PATH ${PATH}:${JAVA_HOME}/bin # Install WSO2 CEP 3.1.0 (manually download it in advance and place it into a 'src' subdirectory below the 'Dockerfile') COPY src/wso2cep-3.1.0.zip /opt/src/wso2cep-3.1.0.zip RUN unzip -q /opt/src/wso2cep-3.1.0.zip -d /opt RUN rm /opt/src/wso2cep-3.1.0.zip # Set environment variables # HOME is already set correctly in centos image # ENV HOME /root WORKDIR /root CMD /opt/wso2cep-3.1.0/bin/wso2server.sh
After the build completed I tagged the image to include my username via docker tag wso2cep-3.1.0:latest dfch/wso2cep-3.1.0:latest
…
… and pushed it to as a new repository dfch/wso2cep-3.1.0 with docker push dfch/wso2cep-3.1.0
.
Note: you have to first perform a docker login
to be able to push the image. Caution: the passphrase is saved on the machine where you push. So be careful where you do that!
After running the image via docker run -d -t -i -p 9443:9443 --name cep dfch/wso2cep-3.1.0
I could launch a browser and login to the application:
Also I am not quite sure how ‘good’ versioning and maintenance can be applied to this image. Maybe it is best to build the complete application from source and not to use the ZIP download at all.
You can use download the image from via docker pull dfch/wso2cep-3.1.0 and you can grab the Dockerfile from our GitHub account.
As this is my first docker attempt (with a 4 hours learning head start), suggestions for improvement are very welcome!
UPDATE 2014-12-24 I also pushed some more images containing:
When you run the image and assign it a name (as in the above example) you have to delete the container to be able to start it a second time (or you omit the --name
option).
The intermediate image wso2cep-3.1.0
can be deleted after the build process completes.
Restarting the server takes quite some time
If you want to expose more ports (like http or jms) you have to specify this in the docker run
command separately.
‘Burning’ the application into the image certainly increases the file size considerably but also speeds up the start up time.
Signing up to docker was very easy (as I already had a GitHub account).
There is no docker cp
equivalent for copying data from the host to the container, so using docker run -v host-path:container-path
seems to be the easiest workaround.
Not applying yum update -y
will reduce the final image size by approx 150MB
The dockerfile could be based on dockerfile / java so that an update to the java machine could be applied automatically (and to be able to choose between java versions, plus saving some space)
Thank you for the post, your instructions helped me a lot!