Over a million developers have joined DZone.

A Two-Container Approach to Set Up a LogicalDOC Instance With MySQL

DZone's Guide to

A Two-Container Approach to Set Up a LogicalDOC Instance With MySQL

With containerization getting more attention, let's incorporate it into document management and databases — in this case LogicalDOC and MySQL.

· Database Zone ·
Free Resource

Slow SQL Server? These SentryOne resources share tips and tricks for not only troubleshooting SQL Server performance issues, but also preventing them before they hit your production environment.

In this article, we will discuss how to set up a LogicalDOC instance with two separate containers. We will use one of them for the document management system itself, and the other one for MySQL, the preferred relational database management system (RDBMS) for use in a production environment. By running these two services in separate containers instead of using a single virtual machine, we will make a much more efficient use of the host resources. Additionally, this is the recommended method to leverage Docker as stated in the official documentation.

As a prerequisite, we must have requested and received an Enterprise version trial license of LogicalDOC previously. To do so, we must fill the request form in the official website.

Note: We will use the word docker (all lowercase) to refer to the containerization technology whereas Docker (first letter uppercase) is the company behind it.

What Is Docker?

In simple terms, docker is a technology that makes it easy to create, deploy, and run applications and all its dependencies in a single package by using Linux containers. This approach ensures that each application will run seamlessly on other machines as it did in the system where it was packaged.

Since docker leverages the features of Linux containers, the result is somewhat like a virtual machine but without the overhead caused by a guest operating system. Using the same hardware, docker allows you to run several containers where otherwise only one virtual machine could be instantiated.

Installing Docker on CentOS 7

The core component of the platform is called the docker engine, which is used to create and run the containers. To install the most updated version from the Docker repository, follow these steps:

Step 1: Remove the docker package, if previously installed from the CentOS repositories. This will not remove any containers previously created:

yum -y remove docker

Step 2: Set up the Docker repository. Although not strictly required, it is worthwhile to install the yum-utils package so that we can have all the tools for manipulating packages through yum handy before.

yum install -y yum-utils

yum-config-manager --add-repo https://docs.docker.com/engine/installation/linux/repo_files/centos/docker.repo

Step 3: Update the existing package index and installed programs. By using the -y flag, the installation will assume that the answer to any question is yes. Thus, programs will be installed and GPG keys imported without any further intervention from us. 

yum makecache fast && yum -y update

Step 4: Install the docker engine:

yum -y install docker-engine

Step 5: Start docker and run the hello-world test image to confirm that the installation was successful:

systemctl start docker

systemctl enable docker

docker run hello-world

The expected output after a successful installation is shown in Fig. 1 where a series of messages are shown in the terminal:

Image title

Now it’s time to create two separate containers to run the database server and LogicalDOC. We will name them ct1-db and ct2-logicaldoc, respectively.

Creating a MySQL-Based Container

Fortunately, there are several ready-to-go containers in the Docker Hub, maintained by Docker. This allows us to easily deploy a MySQL-based container into our docker instance with just one command.

docker run --detach -db --env "" --env="" --env="" --env="" --restart="always" mysql


  • --name indicates the name of the new container, which is a result of deploying the container named mysql from the Docker Hub.

  • --detach tells docker to run the container in the background (as a service).

  • mysql is the name of the image in the Docker Hub.

  • --always will ensure that the container will be started along with the docker service on startup.

  • --env is used to:

    • specify the name of a database to be created when the image is started using MYSQL_DATABASE (logicaldoc),

    • create a database account (ct2 in this case) with superuser privileges over MYSQL_DATABASE,

    • set the MySQL password as MYSQL_PASSWORD (YourPasswordHere), and

    • assign a password for the root account as MYSQL_ROOT_PASSWORD (RootPasswordHere). Although we will not use this account, this environment variable is required while building a container based on the MySQL image.

When you press Enter, the MySQL image will be deployed in our system. Fig. 2 shows the list of containers after the creation of ct1-db and the IP address assigned to it within the docker network. Also, under PORTS we can see that the database server is listening for connections on TCP port 3306:

docker container ps

docker inspect --format '{{ .NetworkSettings.IPAddress }}' ct1-db


Image title

IMPORTANT: Take note of the IP address assigned to ct1-db as we will use it while creating the configuration files to deploy ct2-logicaldoc. For more details on environment variables available for the deployment of the MySQL image, refer to the corresponding Docker Hub documentation.

At this point, we can use the following command on the host to connect to MySQL in ct1-db. For the time being, we will only show the current list of databases:

mysql -u root -pYourPasswordHere -h "SHOW DATABASES;"


Image title

As for LogicalDOC, the available containers in the Docker Hub use an outdated version of the Community Edition. For that reason, we will follow a somewhat different strategy to create ct2-logicaldoc.

Running LogicalDOC Inside a Container

Once the database container is running, we will use another prebuilt image (CentOS 7) to create our own where we will deploy LogicalDOC. In other words, we will provision the generic CentOS 7 image with a LogicalDOC installation.

To create our LogicalDOC image (which we will name logicaldocbuild) in the current working directory we will follow these steps:

Step A: Download the latest Java JDK and the LogicalDOC installation files to the host

Use these commands to download the files:

wget --no-cookies --no-check-certificate --header "Cookie:-securebackup-cookie"http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.rpm

wget https://s3.amazonaws.com/logicaldoc-dist/logicaldoc/installers/logicaldoc-installer-7.6.zip


Step B: Write the Dockerfile

A dockerfile is a plain text file that includes all the docker commands required to build an image. Following the usual Docker convention, we will name it Dockerfile and store it in the current working directory of the host.

The contents of the Dockerfile are as follows:

FROM centos:latest
LABEL maintainer "Gabriel Canepa"
ADD autologicaldoc.sh /opt/
ADD jdk-8u112-linux-x64.rpm /opt/
ADD logicaldoc-installer-7.6.zip /opt/
RUN yum -y install wget unzip && \
cd /opt && \
rpm -Uvh jdk-8u112-linux-x64.rpm && \
unzip logicaldoc-installer-7.6.zip && \
ENTRYPOINT /LogicalDOC/bin/logicaldoc.sh start &&/bin/bash


  • FROM indicates the base image used to build the current one.

  • LABEL is the preferred way to add a label (such as maintainer) to the image.

  • ADD copies a file on the host to the container.

  • RUN executes a command while provisioning the image during the initial build.

  • ENTRYPOINT indicates which action should be run each time a new container is created using this image. In this case, we start the LogicalDOC service. In order to prevent the container for exiting after the logicaldoc.sh script is run, we instantiate a new shell (which will end up running in the background).

  • EXPOSE is used to associate a given port to enable networking between the container and the host.

For more details on the above instructions (and others), you may want to refer to the Dockerfile reference.

Step C: Write the helper shell script.

Next, the following script (autologicaldoc.sh) must be placed in the current working directory as well:


# Script name: autologicaldoc.sh
# Purpose: Unattended configuration of a working installation of LogicalDOC Enterprise

# Date        Version Author        Change description
# ---------- ------- -------------- -------------------------------------------------------
# 2017-02-17 1.0     Gabriel Cánepa    Initial version. Tested with LogicalDOC 7.6 Enterprise.

# Export Java environment variables
export JAVA_HOME=/usr/java/jdk1.8.0_112/jre/
export PATH=$JAVA_HOME/jre/bin:$PATH

# Variables required for configuring LogicalDOC
# When required, 1's are used to continue to the next step
INSTALL_LANGUAGE="0"# 0: English; 1: Italian; 2: Spanish; 3: French; 4: German
TARGET_PATH="/LogicalDOC"# Default installation directory
INCLUDE_CAD="N"# Include optional pack 'CAD Preview' - N: No, Y: Yes
NAME="Gabriel Canepa"
DB_ENGINE=0# 0: MySQL; 1: Oracle; 2: SQL Server; 3: PostgreSQL
DB_USER="ct2"# User with superuser privileges on the logicaldoc database
OPENOFFICE="/opt/openoffice4"# Path to OpenOffice, if installed. Otherwise, leave blank ("").
CONVERT="/usr/bin/convert"# Path to Convert, if installed. Otherwise, leave blank ("").
GHOSTSCRIPT="/usr/bin/gs"# Path to Ghostscript, if installed. Otherwise, leave blank ("").
TESSERACT="/usr/local/bin/tesseract"# Path to Tesseract, if installed. Otherwise, leave blank ("").
CLAMSCAN="/usr/bin/clamscan"# Path to Clamscan, if installed. Otherwise, leave blank ("").
OPENSSL="/usr/bin/openssl"# Path to OpenSSL, if installed. Otherwise, leave blank ("").
PDFTOHTML="/usr/bin/pdftohtml"# Path to PDFTOHTML, if installed. Otherwise, leave blank ("").
CREATE_AUTOINSTALL="N"# Create autoinstall file? N: No; Y: Yes. Not really useful.

# Install LogicalDOC.
# The use of "here documents" helps us to automate the installation.
# This unattended installation has been tested in LogicalDOC Enterprise 7.6.
java -jar logicaldoc-installer.jar <<EOF

Let’s now proceed to create the image. You will see the progress of the build step by step:

docker build -t logicaldocbuild .

Image title

Once the image has been successfully built, we can create and start the container. The following command will do the job: 

docker run --interactive --tty --detach -logicaldoc --restart="always":8080--link ct1-db


  • --interactive, --tty, and --detach handle the starting of the container and ensure it continues running once the configuration script (last line in the Dockerfile) is executed.

  • --publish will expose port 8080 in the container to the same port in the host. This will allow us to access the container through a computer in the same LAN as the host, and

  • --link, followed by the name of the first container, will ensure both remain related even after restarting them, or the docker engine (which usually causes a change in their IP addresses).

Listing the active containers will show ct2-logicaldoc now. Please note that under PORTS, ct2-logicaldoc shows>8080. This indicates that requests made at any IP address of the host on port 8080 will be forwarded to the same port in the said container.

Image title

Finally, launch a browser and go to <IP address of your docker host>:8080. In this case, docker was installed on

Image title

Login with the default credentials (admin/admin - don’t forget to change your password later!) and start enjoying your LogicalDOC Enterprise edition running on top of docker.

This article describes how to create a 2-container setup of LogicalDOC and MySQL with data persistence. That is, all the information stored in the database will survive across reboots. When the VOLUME directive is not specified in the Dockerfile, docker handles stores container data under /var/lib/docker/volumes on the host. However, in a production environment, the use of VOLUME to indicate the path of a dedicated directory (perhaps a network share that is mounted on the host and frequently backed up) is preferred.

Database monitoring tools letting you down? See how SentryOne empowers Enterprises to go faster.

docker ,mysql ,containerization ,database ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}