Featured post

Docker setup for Liferay 7 with MySQL

Friday 24 March 2017

Docker setup for Liferay 7 with MySQL

Docker is among the most famous DevOps tool these days which eliminates “works on my machine”  problem.

Prerequisite:

Docker, Yes, you do not need any developer setup other than Docker!

About: 

Use docker and distribute the same image to your team and start the development. No setup is required like configure liferay,sql, etc.

There are multiple ways to use docker, but easiest is to use yml and docker-compose.
I am using Manuel de la Peña's docker files to make it work.

Download repository from git - https://github.com/mdelapenya/docker-liferay-portal/tree/7-ce-ga3-tomcat-MySQL (If you are using windows, keep your folder in User directory)

Structure:

Folder structure with slight change  is -
Portal ext is placed inside configs and will be copied to your docker file system, you can make require changes in this file.

I have made few changes in docker-compose.yml to add sql port and mount deploy folder.
Do not use tab while changing yml files,use space instead.

version: '2'
services:
  portal:
    build: .
    ports:
     - "8080:8080"
     - "11311:11311"
    volumes:
    - "./data/deploy:/usr/local/liferay-ce-portal-7.0-ga3/deploy"
    depends_on:
     - mysql
  mysql:
    image: mdelapenya/mysql-utf8
    ports:
     - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=my-secret-pw
      - MYSQL_DATABASE=lportal
      - character-set-server=utf8mb4
      - collation-server=utf8mb4_unicode_ci


To start the server all you need to do is use docker terminal or normal command window and move to corresponding directory and run command - "docker-compose up". 





This command will download images from docker hub and create a new image from your local Dockerfile and start your liferay server on 8080 port with MySQL on 3306.

Use docker-machine ip to fetch machine address and then you can hit your portal e.g. 192.168.99.100:8080

While doing docker-compose up if you see this error for memory





Then go to Virtual Box > Settings > System and increase memory and CPU accordingly.You can perform the same thing with config.json of your docker machine.










You need to set port forwarding in Oracle Virtual Box. It is shipped with Docker ToolBox as well.
Oracle Virtual Box > Settings > Network > Advance Port Forwarding.(If you do not want to access it from localhost then leave it)









Now we will go one by one to understand content of the file


  1. version : We are using version 2 of yml.
  2. services: Which services needs to be started. Right now there are two one is portal and other is MySQL.
  3. build: Inside portal we are using build [.] which indicates we are using current directory to build docker image from Dockerfile. In normal case we use image same as MySQL section.
  4. ports: What ports must be exposed to host environment, right now we are accessing portal from 8080, we can change it to 8090:8080 like this.
  5. volumes: We will use this section to deploy war or jar in docker. Just copy your file inside your local folder which you mounted to docker's deploy folder.
  6. depends_on: On which services your service rely, like MySQL.
  7. image: docker URL to fetch image.

To see your volume, port settings and environment, you can use docker inpsect [CONTAINER_ID].

Use "docker ps" to see running containers


Take initial string of container id and run "docker inpsect [CONTAINER_ID]"
e.g. docker inspect b32

Output of this command contains multiple sections - 


Environment Variables like LIFERAY_HOME or JAVA_HOME


Ports / Network Settings


Mounts - In our case we created a folder data/deploy which is mounted to volume liferay/deploy folder.





Some useful commands:

docker-compose up -d: To create image and start docker container in background
docker-compose down: To stop
docker-compose start: To start container from previously created images
docker-compose stop: To stop container and persist the state.
docker images: To list all available images
docker exec -it [CONTAINER_ID] bash: To access file system like putty
docker logs -f  [CONTAINER_ID]: To check logs

Note: You can use unique initial string for CONTAINER_ID e.g. If container id is "234sdfs234" you can use "234".



You are just done, Try & Enjoy the function.............:)