SpringBoot application using MarkLogic as a Docker Container

Reading Time: 4 minutes

In this blog, we will know how we can create a SpringBoot application that uses MarkLogic as the database tier. In this application, we will be running MarkLogic in Docker containers.


A spring boot is an open-source Java-based framework. Spring Boot is a project that is built on top of the Spring Framework. It makes it easy to create stand-alone, production-grade applications that we can just simply run.


MarkLogic Server is an enterprise no sequel database. The unique structure of MarkLogic ensures that your applications are both scalable and have extreme performance. MarkLogic’s Server is a multi-model database. It has documents in place of a schema.


Docker is an open platform for developing and running applications. It’s a set of the platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers often deliver both an application and configuration.



A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"








		<relativePath/> <!-- lookup parent from repository -->






	<description>Demo project for Spring Boot</description>






























We need to add marklogic-client-api dependency under the dependencies section and jcenter repository under the repositories section to use MarkLogic’s Java Client API.


Application.yml is a configuration file that keeps our application configurations.


  host: localhost

  port: 8000

  username: yourusername

  password: yourpassword

Directory Structure

This is what the project structure will look like :

  • config : Config package contains all the configuration files for the project.
  • controller : Controller package contains all the controller class files.
  • entity : The entity package contains all the entities’ class files.
  • repository : Repository package contains all the repository class files.
  • service : Service package contains all the service class files.


package io.knoldus.config;

import com.marklogic.client.DatabaseClient;

import com.marklogic.client.DatabaseClientFactory;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;



public class BasicConfig {


    private String host;


    private int port;


    private String username;


    private String password;


    public DatabaseClient databaseClient() {
        return DatabaseClientFactory.newClient(host, port, new

DatabaseClientFactory.DigestAuthContext(username, password));

  • @Configuration : Configuration annotation which indicates that the class has @Bean definition methods.
  • @EnableAutoConfiguration : EnableAutoConfiguration annotation auto-configures the beans that are present in the classpath.
  • databaseClient() : The databaseClient method helps to create a database client.
  • Internally, the Java Client API maintains a OkHttpClient connection pool that is shared by all DatabaseClient objects.


Docker is surrounding for growing and handling containers. Containers package up programs and their runtime dependencies. Strolling MarkLogic in docker bins keeps its variations isolated from every different. Spinning up a MarkLogic container is fast compared to the time needed for virtual machines to begin.

FROM centos:centos7

RUN yum -y update && yum clean all

RUN yum -y install glibc.i686 gdb.x86_64 redhat-lsb.x86_64 && yum clean all

RUN yum -y install initscripts && yum clean all

ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/MarkLogic/mlcmd/bin

COPY MarkLogic-10.0-9.4.x86_64.rpm /tmp/MarkLogic.rpm

RUN yum -y install /tmp/MarkLogic.rpm && rm /tmp/MarkLogic.rpm

EXPOSE 7997 7998 7999 8000 8001 8002

CMD /etc/init.d/MarkLogic start && tail -f /dev/null


version: '2'



    build: .

    image: ml8:build


      - "7997"

      - "7998"

      - "7999"


      - "8000:8000"

      - "8001:8001"

      - "8002:8002"

      - "8010:8010"

    hostname: "ml1.local"

    container_name: "ml1.local"

Run docker build . command to create a Docker image.

Output :

After creating the image run docker compose up -d

Output :

Now heads towards http://localhost:8001

Output :

then finish the rest of the MarkLogic post-installation steps.


Thanks for Reading !!

Written by 

I am Software Consultant at Knoldus and I am curious about learning new technologies.