Docker with Liferay DXP

February 8, 2017

What is docker?

Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

There are so many advantages using Docker, one for example is that the new members in a development team can easily build a local environment without spend a lot of time. With this in mind, this article shows how to build a MySQL and Liferay DXP development environment with Docker.


This text was written with the idea that the reader knows about how Docker works, despite this I wrote you a brief reminder.


A Docker image is a read-only template with instructions for creating a Docker container


A Docker container is a runnable instance of a Docker image


A docker image is described in text file called a Dockerfile, which has a simple, well-defined syntax


A tool for defining and running multi-container Docker applications.



Build an image from a Dockerfile


Tag an image into a repository


Pull an image or a repository from a Docker registry


Push an image or a repository to a Docker registry


Run a command in a new container

Creating Docker Containers

Data base

As I said, we are going to use mySql as data base in our project. We can download a mySql image from

Executing this command line

docker run --name articleDatabase -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_USER=lportal -e MYSQL_PASSWORD=lportal -e MYSQL_DATABASE=lportal -d mysql:5.7

We get a mySql server, inside a Docker container named articleDatabase, running in localhost:3306. If is required we can connect to the server (lportal as user and password) for data import, execute scripts, alter tables...

Liferay DXP

For creating our Liferay image we can download a clean image of Ubuntu, and manually install java, Liferay DXP, deploy some portlets… or we can use a dockerfile.

We're not going to create a dockerfile from scratch, we're going to use one created by Christian Toncelli. The file was created for working with Lifeay CE bundles, in order to use it with Liferay DXP we must edit it.

Download the project from github

The project is stored in Github, so we must download it. Because in the trunk is the 6.2 version, we must download 7.0 branch, where is the last version of Liferay.

git clone -b 7.0 --single-branch

Now we have in our directory something like this

Configuration port-ext files

Inside the conf folder we have the configurations files, in this files is where data base configuration is placed.

As you can see, the database configuration is using localhost:33006, which is the container we started earlier.

Deploy portlets

At the time the image is built, we can deploy some portlets. For doing this, we must copy them into the deploy folder.


The file named Dockerfile, contains the instruction to build a Liferay image from scratch. This means that using a clean Ubuntu image, Docker will install java and a clean Liferay 7 bundle.

FROM ubuntu:xenial
MAINTAINER Cristiano Toncelli <>
# Users and groups
# RUN groupadd -r tomcat && useradd -r -g tomcat tomcat
RUN echo "root:Docker!" | chpasswd
# Install packages
RUN apt-get update && \
         apt-get install -y curl unzip ssh vim net-tools git && \
         apt-get clean       
# Export TERM as "xterm"
RUN echo -e "\nexport TERM=xterm" >> ~/.bashrc      
# Install Java 8 JDK
RUN apt-get update && \
    apt-get install -y openjdk-8-jdk && \
         apt-get clean
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
# ...

We must change somethings in order to use Liferay DXP, from this

# Install liferay (removing sample application "welcome-theme")
ENV LIFERAY_DIR=liferay-ce-portal-7.0-ga3
ENV TOMCAT_DIR=tomcat-8.0.32
RUN cd /tmp && \
         curl -o ${LIFERAY_DIR}.zip -k -L -C - \
         "" && \
         unzip ${LIFERAY_DIR}.zip -d /opt && \
         rm ${LIFERAY_DIR}.zip && \
         rm -fr ${TOMCAT_HOME}/webapps/welcome-theme && \
         mkdir -p ${LIFERAY_HOME}/deploy && \
         mkdir -p ${LIFERAY_BASE}/script

To this:

# Install liferay (removing sample application "welcome-theme")
ENV LIFERAY_DIR=liferay-dxp
ENV TOMCAT_DIR=tomcat-8.0.32
RUN cd /tmp && \
         curl -o ${LIFERAY_DIR}.zip -k -L -C - \
         "" && \
         unzip ${LIFERAY_DIR}.zip -d /opt && \
         rm ${LIFERAY_DIR}.zip && \
         rm -fr ${TOMCAT_HOME}/webapps/welcome-theme && \
         mkdir -p ${LIFERAY_HOME}/deploy && \
         mkdir -p ${LIFERAY_BASE}/script

What we changed are the url to download the Liferay DXP version and some words (tomcat folder, Liferay folder).

In order to build the image we must execute this command

docker build –t liferayArticle

Now we have a docker image in our computer, for running this image:

docker start liferayArticle

Creating images

At this point we have the development environment running locally (one container with the database and one container with Liferay DXP). The next big step is upload those to mimacom's server.

Execute this instructions for create the tags versions of the containers:

docker tag liferayArticle
docker tag articleDatabase

Because we're not going to upload the images to Docker's hub we must write mimacon's repository address. Keep in mind that in this example the port is not written.

This is the first version, so we use 1 as tag version. During the development process it's possible that you need to upload new versions, for doing this you must change the version of the tag.

To upload the tags to the sever, the commands are:

docker push
docker push

That's all, the two images are available in mimacom's repository (, where everyone can download them.

Note: When your images are uploaded to you must write your user and password, the reason that I don't do this is because I created an insecure Docker repository.

Create docker-compose file

For using easily our images, we are going to create a docker-compose file.

  container_name: liferayArticle
  - VM_HOST=vm-default
  - "2222:22"
  - "1099:1099"
  - "80:8080"
  - "443:8443"
  - "8999:8999"
  - ./deploy-run:/var/liferay/deploy
  - "articleDatabase "
  container_name: articleDatabase
  - "3306:3306"
  - MYSQL_USER=lportal
  - MYSQL_PASSWORD=lportal
  - MYSQL_DATABASE=lportal

Everyone who used this file, creates a development environment in minutes (obviously depends on your network and sever).

Using our docker-compose file

We must configure the docker-compose file before using it because some configurations are different between users.

The most important thing is the volume, which is the folder shared between container and the system operative.

For example, in my windows environment I configured the volume as

  - c:\Projecs\Article\bundles\deploy:/var/liferay/deploy

This means, that every war I copy in c:\\Projects\\Article\\bundles\\deploy is going to be deployed in my Liferay DXP container.

In order to use it, we executed this commands in the directory where there is

docker-compose up –d
docker-compose down
About the author: Carlos García
Join us