Docker LiferayCommunityEdition-Portal 7.0.3 & MYSQL 5.7

We are going to deploy Liferay Community Edition Portal 7.0.3 GA on a Docker container. It can be used as a Development environment, easy and quick to create and recreated.  We will create a network for our container, some volumes, a Database Image based on Mysql 5.7, and the Liferay Image.

NOTE: This articule explain with some details the process about how to create the Docker Liferay environment, if you just want to use a Docker LiferayCommunityEdition, go to https://github.com/felix-centenera/LiferayCommunity7.0.3Docker, and follow README.me documentation ;).
You can download all the project from https://github.com/felix-centenera/LiferayCommunity7.0.3Docker.git

Network:

Create a simple bridge network.

$ docker network create liferay-net

Database mysql 5.7 image:

Create the next structure of folders and files:
-dbmysql (Folder)
– -sql-scripts (Folder)
– – -liferaydb.sql (File)
– -Dockerfile (File)

liferaydb.sql:

CREATE USER 'liferay' IDENTIFIED  WITH mysql_native_password BY 'liferay';
create database liferaymysql character set utf8;
GRANT ALL PRIVILEGES ON liferaymysql.* TO 'liferay'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Dockerfile:

FROM mysql:5.7

# Add a database
ENV MYSQL_DATABASE company

# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
# executed during container startup
COPY ./sql-scripts/ /docker-entrypoint-initdb.d/

Create the  Database Image based on Mysql 5.7 (The script  sql create will be included in the image, the script will create all resources required by Liferay):

$ cd dbmysql
$ docker build -t mysql_liferay:1.0 .

Liferay Liferay Community Edition Portal 7.0.3 GA4 Image:

Create the next structure of folders and files:
-appliferay (Folder)
– -etc(Folder)
– – -portal-ext.properties (File)
– – -portal-setup-wizard.properties (File)
– – -mysql-connect-java-5.1.46.jar (Not created, download this driver from Internet)
– – -setenv.sh (File)
– -Dockerfile (File)

portal-ext.properties:

##DATABASE
#jdbc.default.jndi.name=jdbc/LiferayPool
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://mysql_dev:3306/liferaymysql?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=liferay
jdbc.default.password=liferay

auth.forward.by.last.path=true

editor.wysiwyg.portal-impl.portlet.ddm.text_html.ftl=ckeditora
database.indexes.update.on.startup=true

##
## Redirect
##
#
# Set this property to "ip" or "domain" for the redirect security method. If
# set to "domain", the portal will only redirect users to domains listed in
# the property "redirect.url.domain.allowed". If set to "ip", the portal
# will only redirect to domains whose IP address resolve to an IP address
# listed in the property "redirect.url.ip.allowed".
#
#redirect.url.security.mode=domain
redirect.url.security.mode=domain
# Input a list of comma delimited domains which the portal is allowed to
# redirect to. Input a blank list to allow any domain.
#
#redirect.url.domains.allowed=
#
# Input a list of comma delimited IPs which the portal is allowed to
# redirect to. Input a blank list to allow any IP. SERVER_IP will be
# replaced with the IP of the host server.
#
#redirect.url.ips.allowed=
#ldap.user.custom.mappings.0=phonenumber=OfficePhone

portal-setup-wizard.properties:

admin.email.from.address=test@liferay.com
admin.email.from.name=Test Test
company.default.name=Test
liferay.home=/opt/liferay-portal
setup.wizard.enabled=false

setenv.sh:

JAVA_HOME=/usr/java/latest

CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding=UTF8 -Djava.net.preferIPv4Stack=true -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT"

# Gestion de GC por 1.8 usamos G1C
CATALINA_OPTS="$CATALINA_OPTS -Xmx2120m -Xms2120m "
CATALINA_OPTS="$CATALINA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:InitiatingHeapOccupancyPercent=45"
CATALINA_OPTS="$CATALINA_OPTS -XX:ParallelGCThreads=6 -XX:SurvivorRatio=8 -XX:NewRatio=2"

# Log de GC
CATALINA_OPTS="$CATALINA_OPTS -Xloggc:/opt/liferay-portal/tomcat/logs/logGC.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
CATALINA_OPTS="$CATALINA_OPTS -XX:-UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=20M"

Dockerfile:

# Set the base image CentOS
FROM centos:latest

# Update the repository sources list and install some packages
#RUN yum update && yum install -y unzip && yum install -y wget && yum install -y telnet
RUN yum update -y && yum install -y unzip wget telnet

# Install java8 jdk && Tunning java
RUN wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm" && \
yum localinstall -y "jdk-8u131-linux-x64.rpm" && \
rm -f "jdk-8u131-linux-x64.rpm" && \
update-alternatives --install "/usr/bin/java" "java" "/usr/java/latest/bin/java" 1 && \
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/latest/bin/javaws" 1 && \
update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/latest/bin/javac" 1  && \
sed -i "s/file:\/dev\/random/file:\/dev\/\.\/urandom/g" /usr/java/jdk1.8.0_131/jre/lib/security/java.security

# Download and install liferay
RUN curl -OL  https://sourceforge.net/projects/lportal/files/Liferay%20Portal/7.0.3%20GA4/liferay-ce-portal-tomcat-7.0-ga4-20170613175008905.zip && \
unzip liferay-ce-portal-tomcat-7.0-ga4-20170613175008905.zip -d /opt && \
rm liferay-ce-portal-tomcat-7.0-ga4-20170613175008905.zip && \
ln -s /opt/liferay-ce-portal-7.0-ga4 /opt/liferay-portal && \
ln -s /opt/liferay-portal/tomcat-8.0.32 /opt/liferay-portal/tomcat

# Add configuration files
ADD etc/portal-ext.properties /opt/liferay-portal/tomcat/webapps/ROOT/WEB-INF/classes/portal-ext.properties
ADD etc/portal-setup-wizard.properties /opt/liferay-portal/portal-setup-wizard.properties
ADD etc/setenv.sh /opt/liferay-portal/tomcat/bin/setenv.sh

# Add mysql driver connectos
ADD etc/mysql-connector-java-5.1.46.jar /opt/liferay-portal/tomcat/lib/ext/mysql-connector-java-5.1.46.jar

# Expose port 8080
EXPOSE 8080

# Create user and change permissions
RUN groupadd -r Adminweb && \
useradd -r -u 999 -g Adminweb -d /home/Adminwas -ms /bin/bash Adminwas && \
chown Adminwas:Adminweb -R /opt

#Change user
USER Adminwas
ENV PATH=$PATH:/opt/liferay-portal/tomcat/bin

CMD ["catalina.sh", "run"]

Create the  Liferay Image based on CentOS 7.5 :

$ cd appliferay
$ docker build -t liferaycommunity7.0.3:1.0 .

Run mysql_liferay:1.0 based on MYSQL:5.7

It will create the container and create the volumen mysql_volumen

$ docker run -t -d --net liferay-net --name mysql_dev -e MYSQL_ROOT_PASSWORD=test -v mysql_volumen:/var/lib/mysql --publish 0.0.0.0:3306:3306 mysql_liferay:1.0

Run liferaycommunity7.0.3:1.0 based on CentOS:7.5

It will create the container and create the volumens data_volumen, osgi_volumen.

$ docker run -it -d --net liferay-net --name liferay_dev -v data_volumen:/opt/liferay-portal/data -v osgi_volumen:/opt/liferay-ce-portal-7.0-ga4/osgi --publish 0.0.0.0:8080:8080  liferaycommunity7.0.3:1.0

Follow the logs of Liferay to check that it start properly, you will see the next trace “INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 151102 ms”:

$ docker logs --follow <Container_ID>

Access to Liferay WebConsole

url: http://localhost:8080

user: test@liferay.com

password: test

Deploy a theme:

You can deploy a theme in your liferay container, just download the theme, and copy into the container deploy folder.

docker cp Liferay\ 1975\ London\ Theme.lpkg 087d89c1719e:/opt/liferay-portal/deploy

 

Create a site with the new Theme:

Navigate to Sites, and add a new one base on the new theme.

Check the new theme already working in the new site:

Notes:

You can stop and start your container as much as you want, you will not lose the data, but as we create volumes for some of the data,  you can delete the containers and recreated with the volumes and your data will be there. We did not create a volume for /opt/liferay-portal/tomcat/webapps, so if you deploy specif components as webapps for Liferay and you would like to keep this information in a persistent volume, just create Liferay container with the option -v webapps_volumen: /opt/liferay-portal/tomcat/webapps.

You can login in the container with the next command:

docker exec -it <container_ID> /bin/bash