Building and running OFBiz using Docker

OFBiz includes a Dockerfile which can be used to build a container image for running OFBiz. The container image is built based on the sources already available in the build content, i.e. it only uses sources that you have already downloaded.

If you want to include any plugins in your container image, you must download those plugins before running the build. (See the plugin documentation in README.adoc).

Quickstart

Follow these instructions to qet started building and running OFBiz using Docker.

Build the OFBiz container image

From the sources directory (i.e. the directory containing Docker.md), run

DOCKER_BUILDKIT=1 docker build --tag ofbiz-docker .

Run the OFBiz container

Run the following command:

docker run -it -e OFBIZ_DATA_LOAD=demo --name ofbiz-docker -p 8443:8443 ofbiz-docker

This will start an instance of the ofbiz-docker container, publish port 8443 to localhost, load the OFBiz demo data, and then run the OFBiz server.

Once start up completes, you can access OFBIZ at http://localhost:8443/partymgr

Other container building options

The OFBiz Dockerfile defines a mult-stage build. The default container image produced by the build is named runtime and consists of an unintialized OFBiz installation.

During the first run of a container based on this image, seed or demo data can be loaded, and an admin user created.

The runtime container is the default target of a docker build and can be created with commands similar to:

DOCKER_BUILDKIT=1 docker build --tag ofbiz-docker .

OR

DOCKER_BUILDKIT=1 docker build --target runtime --tag ofbiz-docker .

The Dockerfile also defines another stage, demo, which produces a container image with demonstration data already loaded. This container image may be useful in cases where containers are frequency run and destroyed and the time taken to load demo data is becoming noticeable.

To build a container image pre-loaded with demo data, run:

DOCKER_BUILDKIT=1 docker build --target demo --tag ofbiz-docker .

Container runtime options

The container's behaviour at runtime is controlled via environment variables, ‘hook’ scripts and XML entity import files. These items will only be applied to a container during its first run. Flags stored in /ofbiz/runtime/container_state will prevent the repeated application of these items during subsequent starts of the container.

Use of environment variables, hook scripts and XML entity import files are manged by the docker-entrypoint.sh script.

Environment variables

Environment variables are used in docker-entrypoint.sh to control configuration options for the OFBiz container.

Environment variableDefault valueDescription
OFBIZ_SKIP_INITemptyAny non-empty value will cause the docker-entrypoint.sh script to skip any initialisation steps.
OFBIZ_ADMIN_USERadminSets the username of the OFBIZ admin user.
OFBIZ_ADMIN_PASSWORDofbizSets the password of the OFBIZ admin user.
OFBIZ_DATA_LOADseedDetermine what type of data loading is required. none: No data loading is perfomed. seed: Seed data is loaded. demo: Demo data is loaded.
OFBIZ_HOSTSpecify the hostname used to access OFBiz. If empty then the default value of host-headers-allowed from framework/security/config/security.properties is used.
OFBIZ_CONTENT_URL_PREFIXUsed to set the content.url.prefix.secure and content.url.prefix.standard properties in framework/webapp/config/url.properties.
OFBIZ_ENABLE_AJP_PORTemptyEnable the AJP (Apache JServe Protocol) port to allow communication with OFBiz via a reverse proxy. Enabled when this environment variable contains a non-empty value.
OFBIZ_SKIP_DB_DRIVER_DOWNLOADemptyAny non-empty value will cause the docker-entrypoint.sh script to skip downloading of any database drivers.
OFBIZ_DISABLE_COMPONENTSplugins/birt/ofbiz-component.xmlCommas seperated list of paths to ofbiz-component.xml files of the components that should not be loaded.

Hooks

At various steps of initialisation, the docker-entrypoint.sh script will check for ‘hook’ scripts in various directories.

Users of the container can mount files into these directories and influence the OFBiz startup process.

Only script files with filename extension .sh will be processed. If the file is executable, it will be executed, otherwise it will be sourced.

DirectoryStep
/docker-entrypoint-hooks/before-config-applied.dScripts processed before configuration, such as modifications to property files, are applied.
/docker-entrypoint-hooks/after-config-applied.dScripts processed after configuration modifications have been applied.
/docker-entrypoint-hooks/before-data-load.dScripts processed before data loading is executed. Could be used to apply modifications to data files.
/docker-entrypoint-hooks/after-data-load.dScripts processed after data loading is executed.

Data files

During the data loading step - but after either seed or demo data has been loaded - directory /docker-entrypoint-hooks/additional-data.d will be checked to see if any files are present.

If files are present then the load-data functionality in OFBiz will be executed, specifying the /docker-entrypoint-additional-data.d directory as a data source. Any .xml files in this directory will be treated as a data source and will be imported by the entity engine.

This functionality can be used to pre-load OFBiz with user-specific data, such as a chart of accounts.

Database

By default the OFBiz container will use an internal Derby database, storing database related files in the /ofbiz/runtime volume.

Use of an external database can be configured through environment variables.

Derby

To use the embedded Derby database, ensure all database related environment variables are unset.

PostgreSQL

To use a Postgres database set the OFBIZ_POSTGRES_HOST environment variable.

Environment variableDefaultDescription
OFBIZ_POSTGRES_HOSTunsetHostname of the PostgreSQL database server.
OFBIZ_POSTGRES_OFBIZ_DBofbizName of the ofbiz database.
OFBIZ_POSTGRES_OFBIZ_USERofbizUsername when connecting to the ofbiz database.
OFBIZ_POSTGRES_OFBIZ_PASSWORDofbizPassword when connecting to the ofbiz database.
OFBIZ_POSTGRES_OLAP_DBofbizolapName of the olap database.
OFBIZ_POSTGRES_OLAP_USERofbizolapUsername when connecting to the olap database.
OFBIZ_POSTGRES_OLAP_PASSWORDofbizolapPassword when connecting to the olap database.
OFBIZ_POSTGRES_TENANT_DBofbiztenantName of the tenant database.
OFBIZ_POSTGRES_TENANT_USERofbiztenantUsername when connecting to the tenant database.
OFBIZ_POSTGRES_TENANT_PASSWORDofbiztenantPassword when connecting to the tenant database.

The docker-entrypoint.sh script will download a JDBC driver to access the PostgreSQL server and place the script in the /ofbiz/lib-extra volume. If you wish to skip this step then set the OFBIZ_SKIP_DB_DRIVER_DOWNLOAD environment variable to a non-empty value. This would be useful if you have already placed a suitable database driver in the /ofbiz/lib-extra volume.

Examples of running the OFBiz container

docker run -it -p 8443:8443 ofbiz-docker

Launch the OFBiz container, load the seed data, create the administrator user with name admin and password ofbiz, listen on port 8443 for connections to localhost.

Users can access OFBiz at https://localhost:8443/partymgr

The docker container will remain attached the terminal. Interrupting the container, i.e. pressing Ctrl-C, will trigger a graceful shutdown of the container.

docker run -it -e OFBIZ_DATA_LOAD=demo -p 8443:8443 ofbiz-docker

Launch the OFBiz container, load the demo data, listen on port 8443 for connections to localhost.

The demo data includes the administrator user with name admin and password ofbiz.

docker run -it -e OFBIZ_DATA_LOAD=seed -e OFBIZ_ADMIN_USER=localadmin -e OFBIZ_ADMIN_PASSWORD=TTTTT -p 8443:8443 ofbiz-docker

Launch the OFBiz container, load the seed data, create the administrator user with name localadmin and password TTTTT, listen on port 8443 for connections to localhost.

docker run -it -v 'C:\ofbiz-framework\add-data':/docker-entrypoint-additional-data.d -p 8443:8443 ofbiz-docker

Example of running on Windows.

Launches the container with default seed data and administrator user.

After data is loaded, any .xml files in directory C:\ofbiz-framework\add-data are imported by the OFBiz entity engine.

docker run -it -p 8443:8443 ofbiz-docker

Launch the OFBiz container, load the seed data, create the administrator user with name admin and password ofbiz, listen on port 8443 for connections to localhost.

Users can access OFBiz at https://localhost:8443/partymgr

The docker container will remain attached the terminal. Interrupting the container, i.e. pressing Ctrl-C, will trigger a graceful shutdown of the container.

docker run -it -e OFBIZ_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" -p 8443:8443 -p 5005:5005 ofbiz-docker

Creates a debuggable instance of OFBiz, listening on port 5005.