Featured post

Docker setup for Liferay 7 with MySQL

Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Wednesday, 5 April 2017

Docker setup for Liferay 7 with SMTP, document library and more as Part II

In my previous blog we talked about setting up docker with Liferay and MySQL!


In this blog we will integrate SMTP server inside docker and setup mount for document_library.
We will go through content of Dockerfile which we cloned from repo and made necessary changes.

Few terms we need to understand before jumping to the setup

Dockerfile : Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.


Volume : data volume is a specially-designated directory within one or more containers that bypasses the Union File System.

Mount : A mount point is a directory in a file system where additional information is logically connected  from a storage location outside the operating system’s root drive and partition.

Cool, Let's move forward and have a look on docker-compose.yml


version: '2'
services:
  portal:
    build: .
    ports:
     - "8080:8080"
     - "11311:11311"
    environment:
      - MYSQL_ROOT_PASSWORD=my-secret-pw
      - MYSQL_DATABASE=lportal
      - MAIL_SERVER=mail-server
      - MAIL_SERVER_SMTP_PORT=25
      - MAIL_SERVER_USER_FROM=admin@mail.vipin.org
      - MAIL_SERVER_USER_FROM_PASSWORD=admin
      - MAIL_SERVER_AUTH=true
    volumes:
    - "./data/deploy:/usr/local/liferay-ce-portal-7.0-ga3/deploy"
    - "./data/document_library:/usr/local/liferay-ce-portal-7.0-ga3/data/document_library"
    depends_on:
     - mysql
     - mail-server
  mail-server:
    image: million12/citadel
    ports:
      - "25:25"
      - "110:110"
      - "143:143"
      - "465:465"
      - "587:587"
      - "993:993"
      - "995:995"
      - "9090:8080"
      - "10022:22"
    environment:
      - ROOT_PASS=root
      - PASSWORD=admin
      - DOMAIN=vipin.org
    hostname: mail.vipin.org
  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

This is the same file which we used earlier with addition of mail server setup and mounting document library.

SMTP

We are using million12/citadel repository for SMTP server. There are so may smtp server available in docker hub but this is a easy one with web ui and authentication support.

As you can see in yml file we have added one more dependency service mail-server.  We have exposed ports for smtp, ssl, web ui etc. hostname is your mail extension here.
So you create a user inside smtp server with web support which is available on port 9090, e.g. 192.168.99.100:9090

You can login as admin/admin for administrator account or create user from outside with Register New User link, e.g. vipin.bardia@mail.vipin.org.
Use the same user and create that account in Liferay portal and check on the same mail id if you get a welcome mail like this or not.



Amazing, now you have your own SMTP server with few lines of configuration :)

Document Library

Let's talk about Volume and Mount again. I've already shared there definition above so will go through the use of it in our case.

Let's say I want to move my server to somewhere else, what is required other than database?
It's my documents which is stored in data/document_library folder.

So what can I do about this?

- "./data/deploy:/usr/local/liferay-ce-portal-7.0-ga3/deploy"
- "./data/document_library:/usr/local/liferay-ce-portal-7.0-ga3/data/document_library"

As you can see here ./data/document_library  is my local folder where [.]  represents current directory and /usr/local/liferay-ce-portal-7.0-ga3/data/document_library is my document library folder which is separated by [:] this line creates a volume inside docker container and mount it our local folder.

Whenever we upload anything like this in Liferay


It will be synced to our local folder like this

In the same manner we mount deploy folder and as soon as we drop the file war/jar inside it, it is copied to volume deploy folder and starts deployment.


Dockerfile: These are instruction which is executed step by step to create a new image.


FROM mdelapenya/liferay-portal:7-ce-ga3-tomcat-hsql
MAINTAINER Manuel de la Peña <manuel.delapenya@liferay.com>

COPY ./configs/portal-ext.properties $LIFERAY_HOME/portal-ext.properties

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


  1. Fetch image from repository
  2. Information about Maintainer
  3. Copy portal-ext to docker image at specified path
  4. $LIFERAY_HOME is environment variable
  5. Entrypoint will execute catalina


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

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.............:)