Setting up Liferay locally with Docker seems simple until you're three weeks into a project and every change costs you ten minutes of waiting. The container starts up fine, but every time you touch a module you have to rebuild the entire image, or worse, restore the database manually because someone ran a migration they shouldn't have. That's the point where you can tell whether the development environment was carefully thought out or thrown together in a hurry.
At Julditec we've spent years putting Liferay DXP portals into production, and most of the productivity issues we see in development have to do with how the Docker environment wrapping Liferay is organized, more than with the product itself. Here's what works for us.
Two Dockerfiles, two different responsibilities
The usual mistake is having a single Dockerfile that tries to serve both for building the production image and for developing locally. It works, but it forces you to rebuild heavy layers every time you change a configuration line. We split that responsibility into two files with explicit names.
Dockerfile-dev.dockerfile starts from the base Liferay image and adds only what the local environment needs: development configurations, self-signed certificates if HTTPS is needed, and open remote debugging ports.
FROM liferay/dxp:2024.q2.0
COPY configs/docker/portal-ext.properties /mnt/liferay/files/portal-ext.properties
COPY deploy/dev /mnt/liferay/deploy
ENV LIFERAY_JPDA_ENABLED=true
EXPOSE 8000Dockerfile.ext serves a different purpose: it packages the custom extensions and modules that get deployed on top of that base, so you can rebuild just that layer when you change code, without touching the base Liferay image. With the two layers separated, a change in a module shows up in seconds instead of minutes.
FROM julditec/liferay-dev-base:latest
COPY modules/build/libs/*.jar /mnt/liferay/deploy/
COPY ext/build/libs/*.lpkg /mnt/liferay/deploy/They're different layers. The usual mistake is treating them as alternatives and picking one for the whole project, when the sensible thing is to decide case by case, even screen by screen.
The same applies here: the base image changes rarely, the modules change constantly. If you mix them in a single Dockerfile, you pay the cost of rebuilding everything every time you touch a line of Java.
Restoring backups without losing half an afternoon
When you're testing a data migration, a bulk import script, or any change that touches the schema, you need to get back to the starting point without drama. We follow a simple naming pattern for the data volumes: liferay-data-before-<date>-<description>.
Before any destructive operation, we take a snapshot of the data volume with that name:
docker run --rm \
-v liferay-data:/data \
-v $(pwd)/backups:/backup \
busybox tar czf /backup/liferay-data-antes-20240613-migracion-asset.tar.gz /dataAnd to roll back, you just restore that volume onto a new one and point the compose file to it:
docker volume create liferay-data-restaurado
docker run --rm \
-v liferay-data-restaurado:/data \
-v $(pwd)/backups:/backup \
busybox tar xzf /backup/liferay-data-antes-20240613-migracion-asset.tar.gz -C /dataThe name with date and description may seem like a minor detail, but when you've got ten backups piled up in a folder, it's the only thing that lets you know in seconds which one corresponds to which test without having to open each one.
Portals and applications built to last for years. And someone to maintain them.
We build and maintain portals, intranets and applications. And we rescue existing ones: we update them, tidy them up and leave them maintainable.
See portals and developmentDifferent configurations depending on the environment
Liferay reads configuration in a cascade, and you can take advantage of that to avoid mixing development settings with pre-production ones. We maintain a base portal-ext.properties and environment-specific files that get mounted depending on the active profile.
include-and-override=portal-ext-dev.propertiesIn development, that file enables detailed logging, disables template caching, and points to simulated external services. In a pre-production environment, the same docker-compose mounts a different file, without touching a single line of application code.
services:
liferay:
build:
dockerfile: Dockerfile-dev.dockerfile
volumes:
- ./configs/dev/portal-ext-dev.properties:/mnt/liferay/files/portal-ext-dev.propertiesKeeping configuration separate from code is what lets the same container behave differently depending on where it's deployed, without recompiling anything.
Deploying fast with blade gw deploy
If you work with Liferay Workspace, the blade gw deploy command is the shortcut that avoids rebuilding the entire Docker image every time you change a module. It compiles the module with Gradle and copies it directly to the deploy folder that Liferay watches, without going through docker build.
blade gw :modules:mi-modulo:deployFor it to work, you need to mount that deploy folder as a volume in the docker-compose, so that the container sees it in real time:
volumes:
- ./modules/mi-modulo/build/libs:/mnt/liferay/deployWith this, the cycle of code change, compilation, deployment and testing is reduced to seconds, because Liferay detects the new jar in the watched folder and hot-deploys it, without restarting the container.
Tricks to avoid waiting between each test
Beyond hot deployment, there are several settings that genuinely shorten the change-and-test cycle:
- •Disable unnecessary plugin reloading while developing a single module, using module.framework.properties.jsp.check.interval=0 only in the development environment.
- •Use blade gw deploy -w when available, so it compiles and deploys automatically with every save, without having to run the command manually.
- •Avoid restarting the entire container after every minor configuration change: many portal-ext.properties properties reload without a restart if the change is made to the file mounted as a volume.
None of these tricks replace having properly separated Dockerfiles. They're fine-tuning that only pays off if the base is already organized: if your development image takes eight minutes to build because it mixes layers that shouldn't be together, hot deploy doesn't make up for that lost time.
If you're setting up a local Liferay environment from scratch, start by separating the base image from the extensions and define your backup naming pattern before the first test migration. That order of operations is what keeps you from losing an entire afternoon rebuilding what was already working.
