Deploy WSO2 DS or DAS on Custom Docker in WSO2 Integration Cloud — Part 2

Sajitha Liyanage
5 min readDec 8, 2017

From the previous tutorial we have discussed how to configure the WSO2 DAS or DS before deploy to the integration cloud.

Tutorial 1

In this tutorial lets see how to push WSO2 DAS or DS as docker image and pull it on the WSO2 Integration Cloud custom docker instance.

Lets us first start with the overall flow of docker, which goes like this,

  1. You need to create a Dockerfile with step by step instructions
  2. Then you need to use docker build command to create a docker image based on the Dockerfile that you have created in point 1.
  3. Then you need to use docker login command to log relevant docker repository
  4. Then you need to use docker push command to push your image to that global docker repository

with this information, lets start the work!

Step 1 :-

Open your terminal (Ctrl + Alt + t) and create a folder named docker-images as shown below. This will be our root folder where we will create our Dockerfile.

sajitha@sajitha-ThinkPad:~$ mkdir docker-images

Then navigate to docker-images folder using cd command. Next open your vim, nano or any relevant editor and past the below commands to it and save it named as Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

FROM java
MAINTAINER <your-name> (sajithal@domain.com)
# Update packages and install dependencies.
ENV hostname <hosting-domain>
RUN mkdir -p /wso2
COPY wso2das-3.1.0.zip /wso2
RUN cd /wso2 && \
unzip wso2das-3.1.0.zip && \
rm wso2das-3.1.0.zip
COPY bootstrap.sh /wso2/wso2das-3.1.0/bin
RUN useradd -ms /bin/bash wso2user \
&& chown -R wso2user /wso2 \
&& chmod -R 0774 /wso2
USER wso2user
ENTRYPOINT ["/wso2/wso2das-3.1.0/bin/bootstrap.sh"]EXPOSE 9763 9443 8280 8243

Docker image is nothing but a series of layers built on top of each other, we start with a base image. Let I describe the above commands one by one. The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction. MAINTAINER instruction sets the Author field of the generated images. This is a good practice. ENV instruction sets the environment variable <key>to the value <value>. Here I’m set my hosting domain as env key of hostname. RUN instruction will execute any commands in a new layer on top of the current image and commit the results. Here I create a folder called wso2 first. COPY instruction copies new files or directories from <src> and adds them to the file system of the container at the path <dest>. It’s already same as bash command. Here I copy my wso2das-3.1.0.zip folder to wso2 folder. Then using RUN instruction I do navigate to wso2 folder, unzip the wso2das-3.1.0.zip file and remove the zip file. Then I copy the boostrap.sh file to wso2 folder using COPY instruction. Then with RUN instruction I create a user and grant relevant privileges to that user. USER instruction sets the user name (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile. ENTRYPOINT allows you to configure a container that will run as an executable. Here I set the ENTRYPOINT to “/wso2/wso2das-3.1.0/bin/bootstrap.sh”. EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified.

Now we need to create boostratp.sh file. Again open your terminal editor and past below code to it and save it as boostrap.sh.

#!/bin/bashgrep -rl 'your-domain' /wso2/wso2das-3.1.0 | xargs sed -i 's/your-domain/'"$hostname"'/g'echo "Setting environment parameters completed."sh /wso2/wso2das-3.1.0/bin/wso2server.sh -dashboardNode

boostrap.sh file is need to set the environment variable in the docker container and run the wso2server.sh bash shell file.

Now we need to copy pre-configured (as in tutorial 1) wso2das-3.1.0.zip file to the docker-images folder. After all the works if we run the ls command in docker-images folder i should be like this.

sajitha@sajitha-ThinkPad:~/docker-images$ ls
wso2das-3.1.0.zip bootstrap.sh Dockerfile

So now all done, remain is run docker commands. lets do that. First build the docker image using build command. Here we use squash command (Squash newly built layers into a single new layer).

sudo docker build -t <username>/<repo-name> --squash .

You can see it’s running like this.

sajitha@sajitha-ThinkPad:~/Desktop/docker-images$ sudo docker build -t myimages/dbserver --squash .

Sending build context to Docker daemon 463.6MB
Step 1/12 : FROM java
---> d23bdf5b1b1b
Step 2/12 : MAINTAINER Sajitha Liyanage <sajithal@domain.com
---> Using cache
---> ac29c91e852e
Step 3/12 : ENV hostname domain.com
---> Using cache
---> c0a0dbe245d1
Step 4/12 : RUN mkdir -p /wso2
---> Using cache
---> 69044c919338
Step 5/12 : COPY wso2das-3.1.0.zip /wso2
...............

After finish this command login to the docker account.

sudo docker login -u <username> -p <password>

Then after seeing “Login Successfully” message we can push the docker image to the global repo. This command will take some time but depends with network connection.

sudo docker push <username>/<repo-name>

Step 2 :-

After finish the push command we need to log into WSO2 Integration cloud. Then navigate to “CREATE APPLICATION -> CUSTOM DOCKER -> MANAGE IMAGES”. There is a button called Update that can update our previous created docker instance. So press Update button now. It will pull the docker image from docker-hub relavent repo based on what we gave the details in docker instance.

Congratulations!!

Now we have successfully pushed the docker image into the WSO2 Integration Cloud. Now only remain thing is start the docker. For that go to the docker instance that you created and press Start button.

Yeppy! It’s seems like up and running now. You can navigate to Log and see logs while server starts. (Don’t forget to Enable Tailing).

Stay tuned :)

--

--

Sajitha Liyanage

Software Engineer @ WSO2 | Open Source Contributor | Computer Science Graduate @ UCSC