Introduction
Nowadays, working with platforms like Liferay can get tricky when setting up across different environments. That’s where Docker comes in. It’s a practical way to keep things consistent, whether you’re developing locally or deploying in production.
Using Docker, you can bundle up Liferay and all its dependencies neatly, which saves time and avoids the usual “it works on my machine” issues. And when you bring PostgreSQL into the mix, things get even smoother, especially for setups where you need a reliable backend and can’t afford to lose data.
Why Use Docker for Liferay + PostgreSQL?
One major plus is data persistence. With Docker volumes, your data doesn’t vanish even if you shut down a container. That’s a big deal for content-heavy systems like Liferay, where every piece of data matters. Combined with PostgreSQL, you get a sturdy foundation for development and production.
Prerequisites
Before jumping in, make sure you’ve got the following ready:
- JDK 11 or newer
- PostgreSQL
- Docker and Docker Compose are installed
Environment Requirements
To proceed with this setup, you should have:
- Docker
- Containerization engine
- Docker Compose
- Tool for defining and running multi-container Docker applications
Setting Up Liferay Docker for Connecting to PostgreSQL
Step 1 : How to start Liferay with Docker
If you are unaware of Liferay on Docker, start learning the basics. Follow this step-by-step guide to set up Liferay using Docker (click here):
Step 2 : Create Your Folder Structure
Start by organizing your project directory. Here’s a recommended folder structure:
SERVER/
├── docker-compose.yaml
└── volumes/
├── liferay/
│ ├── data/
│ ├── deploy/
│ ├── osgi/
│ ├── tomcat/
│ │ └── bin/
│ └── portal-ext.properties
└── postgres/
└── data/

This structure helps in managing mounted volumes clearly for both Liferay and PostgreSQL.
Step 3 : Create and Configure docker-compose.yaml
Here’s the configuration you can place inside your docker-compose.yaml:
services:
postgres:
image: postgres:13
container_name: postgres1
ports:
- '5433:5432'
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: ignekBLOG
volumes:
- ./volumes/postgres/data:/var/lib/postgresql/data
networks:
- default
liferay:
image: liferay/portal:7.4.3.120-ga120
container_name: liferay1
ports:
- "8010:8010"
- "8082:8080"
- "8443:8443"
- "11311:11311"
environment:
LIFERAY_JPDA_ENABLED: "true"
JPDA_ADDRESS: 8000
JPDA_TRANSPORT: dt_socket
LIFERAY_RETRY_PERIOD_JDBC_PERIOD_ON_PERIOD_STARTUP_PERIOD_DELAY: 10
LIFERAY_RETRY_PERIOD_JDBC_PERIOD_ON_PERIOD_STARTUP_PERIOD_MAX_PERIOD_RETRIES: 10
LIFERAY_JVM_OPTS: "-Xms4096m -Xmx8192m"
depends_on:
- postgres
volumes:
- ./volumes/liferay/data:/opt/liferay/data
- ./volumes/liferay/portal-ext.properties:/opt/liferay/portal-ext.properties
- ./volumes/liferay/deploy:/opt/liferay/deploy
- ./volumes/liferay/osgi/modules:/opt/liferay/osgi/modules
- ./volumes/liferay/osgi/war:/opt/liferay/osgi/war
networks:
- default
networks:
default:
external:
name: test
Step 4 : Know about the Docker Compose Configuration
- Volumes
- These are used to persist data. Even if the container is removed, the data inside the volume remains safe.
- Ports
- Maps internal container ports to your host machine. For example, 5433:5432 means that PostgreSQL is accessible locally on port 5433.
- Networks
- Allow containers to communicate with each other using service names like Postgres.
- Depends_on
- Ensures the PostgreSQL container is started before Liferay attempts to connect.
Step 5 : Properties for the portal-ext file for database connectivity
To enable Liferay to connect with PostgreSQL, you need the following database properties inside portal-ext.properties:
jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://postgres:5432/ignekBLOG
jdbc.default.username=root
jdbc.default.password=root
Note: Even if PostgreSQL is mapped to port 5433 on your local machine, within the Docker network, Liferay communicates using the internal container port 5432.
Step 6 : Operating Liferay with PostgreSQL using Docker.
To start your setup:
Open your terminal and navigate to the project directory.
sudo docker-compose up
This triggers the Liferay and PostgreSQL containers at once.

To manage containers:
List containers
sudo docker ps -a

//Stop containers
sudo docker-compose down
//OR
Press Ctrl + C
Step 7 : Connecting to the PostgreSQL Database
Once your containers are up, you can access PostgreSQL inside the container:
sudo docker exec -it /bin/bash
//In our case, it is
sudo docker exec -it postgres1 /bin/bash

Inside the bash shell:
psql -U root -d ignekBLOG
To view tables:
\dt

You can also be getting the logs of Liferay with your image name when you compose up the image:

Step 8 : Accessing the Liferay Portal
Open your browser and navigate to http://localhost:8082
You’ll be greeted with the Liferay welcome page. From here, complete the setup wizard or sign in if already configured.

Now navigate to the Control Panel > Server Administrator > Properties > Portal Properties.
And type jdbc.default.url into the search field. You can notice from the image below that you are successfully connected to PostgreSQL.

Conclusion
Using Docker to configure Liferay with PostgreSQL streamlines the development process while improving reliability by isolating dependencies and retaining vital data. This arrangement is ideal for teams working on enterprise portals who require a consistent and repeatable development environment. Volume mounts and container orchestration enable you to create a strong and scalable platform for your Liferay projects.