Leveraging Docker

Docker has become increasingly popular in today’s development lifecycle, by providing an automated way to package software and its dependencies into a standardized unit that can be shared cross-platform. Read Docker’s extensive documentation to learn more.

Liferay provides Docker images for

You can pull Liferay’s Docker images from those resources and manage them yourself. Liferay Workspace, however, provides an easy way to integrate Docker development into your existing development workflow with preconfigured Gradle tasks.

In this tutorial, you’ll learn how to do the following tasks within a workspace:

Creating a Liferay DXP Docker Container

  1. Choose the Docker image you need. This is configured in your workspace’s gradle.properties file by customizing this property:

    liferay.workspace.docker.image.liferay
    

    To find the possible property values you can set, see the official Liferay DXP Docker Hub’s Tags section (e.g., Liferay Portal Docker Tags. For example, if you want to base your container on the Liferay Portal 7.1 GA2 image, you would set this property:

    liferay.workspace.docker.image.liferay=liferay/portal:7.1.1-ga2
    
  2. Run the following command from your workspace’s root folder:

    ./gradlew createDockerContainer
    

This command creates a new container named [projectName]-liferayapp. A new build/docker folder is generated in your workspace. This folder is mounted into the container’s file system. This means files in workspace’s build/docker folder are also available in the container’s /etc/liferay folder.

Any projects in your workspace are automatically compiled and copied to the build/docker/deploy folder when the container is created; this means that when the container is started, all your projects are deployed to the container. All configurations are also applied to the container. You’ll learn more about configuring your container next.

Configuring the Container

Before starting your container, you may want to add additional portal configurations. This could include things like

  • Property overrides (e.g., portal-ext.properties)
  • Marketplace app overrides
  • App server configurations
  • License files

You can do this by applying files (and their accompanying folder structures, if necessary) to your workspace’s configs/docker folder. This folder is treated as your Liferay Home for Docker development; you add additional files that overlay your workspace’s configs/common folder and your Liferay DXP container’s default configuration.

For example, to enable the Gogo shell for your container, add a configs/docker/portal-ext.properties file to your workspace with the following configuration:

module.framework.properties.osgi.console=0.0.0.0:11311

This lets you access your container using Gogo shell via telnet session.

Once the container is started, the configurations stored in configs/commmon and configs/docker are transferred to the build/docker/files folder, which applies all configurations to the container’s file system. For more information on workspace’s configs folder, see this section.

Next, you’ll explore the commands for interacting with the container.

Interacting with the Container

startDockerContainer: starts the container.

logsDockerContainer: prints the portal runtime’s logs. You can exit log tracking mode while maintaining a running container (e.g., [Ctrl|Command] + C).

dockerDeploy: deploys the project to the container’s deploy folder by copying the project archive file to workspace’s build/docker/deploy folder. This command can also be executed from workspace’s root folder to deploy all projects and copy all Docker configurations (i.e., from the configs/common and configs/docker folders) to the container.

stopDockerContainer: stops the container.

removeDockerContainer: removes the container from Docker’s system.

Next, you’ll learn how to build a custom image.

Building a Custom Liferay DXP Image

You can preserve your container’s configuration by building it as an image. To build your custom Liferay DXP image, run

./gradlew buildDockerImage

A Dockerfile is generated for your container when building your image. To do this manually, run

./gradlew createDockerfile

The Dockerfile is generated in your workspace’s build/docker folder. For more information on how to configure the Dockerfile, see Docker’s Dockerfile reference documentation.

Your custom image is now available! Run docker image ls to verify its availability.

You can now manage Liferay’s Docker images in Liferay Workspace!

« Validating Modules Outside of WorkspaceUpdating Liferay Workspace »
Was this article helpful?
0 out of 0 found this helpful