How to Setup Liferay Docker to Connect with PostgreSQL

blog-banner

In this tutorial, we will walk you through setting up Liferay with PostgreSQL using Docker Compose. This setup will help you quickly deploy a Liferay environment backed by a PostgreSQL database, providing a robust platform for enterprise content management and digital experience.

Prerequisites:

  • Basic Knowledge about Docker and Docker Compose and installed both in the system.

Step 1: Creating Folder Structure:

Create a folder structure like the screenshot below for the folder structure of the server.

structure of the server

Step 2: Creating docker-compose.yml file:

First, create a docker-compose.yml file in your working directory. This file defines the services, networks, and volumes for your Docker setup. Below is the configuration file we'll be using:

configuration file

Step 3: Creating Portal-ext.properties file in Liferay folder

  • jdbc.default.driverClassName=org.postgresql.Driver
  • jdbc.default.url=jdbc:postgresql://postgres:5432/postgresDb
  • jdbc.default.username=root
  • jdbc.default.password=root

Step 4: Understanding the Configuration

  • Services: In Docker Compose, a "service" refers to a containerized application or component of your application stack. Each service can be configured independently with its own set of parameters.
    • Image: Specifies the Docker image used for each service (postgres:13 for PostgreSQL and liferay/portal:7.4.3.69-ga69 for Liferay). The image provides the base software environment for the container.
    • Container Name: Provides a custom name for each Docker container (postgres1 for PostgreSQL and liferay1 for Liferay). This name can be used to reference the container in Docker commands.
    • Ports: Maps ports from the host machine to the container (5432:5432 for PostgreSQL and 8080:8080, 11311:11311 for Liferay). This allows external access to services running inside containers.
    • Environment: Sets environment variables needed by each service. For example, database credentials for PostgreSQL (POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB) and JVM options for Liferay (LIFERAY_JVM_OPTS).
    • Volumes: Mounts directories from the host machine to the container (./volumes/postgres/data:/var/lib/postgresql/data for PostgreSQL data persistence and various mounts for Liferay). This ensures that data can be persisted beyond the lifecycle of the container.
    • Depends On: Defines dependencies between services (liferay depends on postgres to ensure PostgreSQL is started first). This helps orchestrate the startup order of interconnected services.
    • Networks: Specifies the network configuration for services (default network named test), allowing containers to communicate with each other over defined networks.

Step 5: Run Docker-compose up command

  • Open your terminal, navigate to the directory containing docker-compose.yml, and run the following command:
  • docker-compose.ymlThis command will start both PostgreSQL and Liferay containers as defined in your configuration file. Check the below logs screenshots it indicates that server is started.
  • server is startedTo check the database and tables from docker execute all the below commands in your terminal.
    • docker ps
    • docker exec -it <Container Id or Name of image> /bin/bash (i.e. in our case cfbe8446ed90 or postgres1)
    • psql -U root -d postgresDb (Where root is userName and postgresDb is DatabaseName)
    • \dt: this command is used for checking the list of tables available in database.

Step 6: Accessing Liferay Portal

  • Once Docker Compose has started the containers, you can access the Liferay Portal by opening your web browser and entering the following URL: http://localhost:8081/ it will redirect to the liferay portal’s home page
  • If you configured a different port number in your docker-compose.yml file, adjust the URL accordingly. This will redirect you to the Liferay Portal's home page, where you can begin configuring and developing your digital experience platform.
  • Go to Server Administrator’s properties from the Control panel and search jdbc. This will show you the all the properties for successful database connection.
  • successful database connection

 

Conclusion:

Setting up Liferay Portal with PostgreSQL using Docker Compose provides a scalable and efficient environment for Liferay Portal Development and managing enterprise-grade applications. By following this tutorial, you've learned how to integrate these technologies seamlessly, enhancing your capabilities in digital experience management and content delivery.

Contact us

For Your Business Requirements

Text to Identify Refresh CAPTCHA
Background Image Close Button

2 - 4 October 2024

Hall: 10, Booth: #B8 Brussels, Belgium