What is Docker ?
Docker is a computer program that performs operating-system-level virtualization also known as containerization. Docker container wraps a piece of software in a complete filesystem that contains everything needed to run: system tools, system libraries, code – anything that can be installed on a server. Which ensures that the software will always run the same, regardless of its environment.
Docker is extremely helpful to rapidly re-create identical development environments on any machine by using container images. A 2016 analysis found that a typical Docker use case involves running five containers per host, but that many organizations run 10 or more.
In this blog, we will create and build a custom Liferay CE docker image (Single node) from our existing Liferay-ce-portal-7.0-ga3, and explain how to run it in our Linux Ubuntu environment.
We need Liferay app integrated with Tomcat and Mysql, We will run Mysql in one container and Liferay over tomcat in another container.
In my case, I had existing Liferay-ce-portal-7.0-ga3 running on my local machine with Mysql database, which I will use to copy in the docker image.
Follow below steps:
A very first thing we need to do is to install Docker on our Linux Machine, Please go to the official documentation and follow every step. In our case, We are going to install Docker CE in Ubuntu. https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/
Verify docker version in order to make sure docker being installed
Update existing files:
We need to update following files from our existing Liferay portal.
In the above file, we need to specify liferay.home to be pointing to our installation location in the docker image.
In the above file, we need to update jdbc.default.url to point to our mysql_1 container name, Which we are going to create later in this blog.
Dockerfile is used to create a custom docker image, Where we can specify installation and other environmental setup details.
##Dockerfile to build Liferay Community Edition Portal 7.0.3 GA3
##Based on ubuntu 14.04
# Set the base image to ubuntu
# Install Java 8 JDK
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:webupd8team/java -y && \
apt-get update && \
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
apt-get install -y oracle-java8-installer && \
#create the folder to contain bundled Liferay tomcat files, it is an absolute path
RUN mkdir -p /usr/liferay/docker/appserver/LR-CE-PORTAL-7.0-GA3
#Copy the LR tomcat bundle folders/files to container
COPY LR-CE-PORTAL-7.0-GA3/ /usr/liferay/docker/appserver/LR-CE-PORTAL-7.0-GA3/
#MAKE the whole Tomcat folder as the mounted directory
# Expose port 8080
Save the file as “Dockerfile” at the same location of your “LR-CE-PORTAL-7.0-GA3” directory, which you want to copy in docker image. In the above docker file we are creating an image from ubuntu:14.04, installing Java 8 and setting up environment variables and copying our existing LR-CE-PORTAL-7.0-GA3 bundle.
Now, We will create an image from our Dockerfile. One thing to make sure that the below command should be run from the same location where you have your Dockerfile.
sudo docker build -t lr-ce-portal-7.0-ga3 .
Building image will take few mins, once it’s completed successfully you could see a message as per the screenshot and can list all images.
We need to create a network, where our multiple containers can communicate.
sudo docker network create liferay-mysql
Next step is to create mysql container, we will not create custom mysql image as official images from the mysql repository are available, will use the latest mysql image.
Before proceeding to this step, we need to create an external volume for our mysql.
mkdir -p /home/st41/Projects/Liferay-Learning7.0/volumes/mysql
sudo docker run -t --net liferay-mysql --name mysql_1 -e MYSQL_ROOT_PASSWORD=test -v /home/st41/Projects/Liferay-Learning7.0/volumes/mysql:/var/lib/mysql --publish 0.0.0.0:3306:3306 -d mysql:latest
mysql_1 container has been created successfully, now we need to export our existing database (which was being used by your existing Liferay instance), you can either use MySql Workbench or search for a command to export.
I will login to our mysql_1 container and create “LR_70” database.
sudo docker exec -it mysql_1 bash
mysql -u root -p
create database LR_70 character set utf8;
A database is created in the mysql_1 container, Now we need to import our database export file, I have imported it using MySql Workbench and our container is ready to serve.
Next step would be to create liferay container from liferay image we created earlier, Please verify the name of an image before executing the command.
sudo docker image ls
sudo docker run -it --net liferay-mysql --name liferay_07 -p 0.0.0.0:8080:8080 -d lr-ce-portal-7.0-ga3:latest
To verify if the container is running or not run following command.
You can see in the above screenshot our both the containers are up and running. The final step is to login to liferay_07 and start our server.
sudo docker exec -it liferay_07 bash
Wait for few mins until the server is up and running.
Finally !!! , You have now a Liferay instance running on docker.
Happy Dockering ;)
For professional paid support, you may contact us at