Skip to Content
Technical Articles
Author's profile photo Shankar Gomare

Deploy SAP HANA based Applications on docker Swarm cluster

In this article we will learn how to containerize web applications and docker swarm cluster deployment of containerized applications.

Icons courtesy

This is second part of “A different take on SAP HANA Express and Docker containers” series, here is first part of this article :

In first article we did installation of docker container, SAP HANA Express on docker container and OpenCart on HDB.

This article contains two parts:

  1. Containerize Web Application
  2. Deploy Web Application on Docker Swarm cluster

Again you have two options, you can see it in action in the below two videos or continue reading.

Icons courtesy and

Icons courtesy and


Since, you have opted to read, let’s get started.

We will containerize standalone OpenCart installed earlier, so it can be deployed on Docker swarm cluster.

Let’s resume from last article, the first step is to build a docker image so we can push to a repository for Docker Swarm use.

We need three things to build docker image for OpenCart, a base docker image, web-server and PHP. These requirements can fulfilled by using a single base image “php:7.4.13-apache-buster”. It contains Debian as base OS, Apache as a web-server and PHP7.4.

Now all we need to do is create a docker build file. I will make it easy for you by positing my docker file below. All the scripts required for this article are available on my github repository

FROM php:7.4.13-apache-buster
COPY src/ /var/www/html/
RUN chmod 777 -R /var/www/html/opencart/

ENV APACHE_DOCUMENT_ROOT /var/www/html/opencart/upload
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

RUN set -ex; \
        docker-php-source extract; \
        { \
                echo '#'; \
                echo 'AC_DEFUN([PHP_ALWAYS_SHARED],[])dnl'; \
                echo; \
                cat /usr/src/php/ext/odbc/config.m4; \
        } > temp.m4; \
        mv temp.m4 /usr/src/php/ext/odbc/config.m4; \
        apt-get update; \
        apt-get install -y --no-install-recommends unixodbc-dev; \
        docker-php-ext-configure odbc --with-unixODBC=shared,/usr; \
        docker-php-ext-install odbc;

RUN apt-get update && apt-get install --no-install-recommends unixodbc unixodbc-dev -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        libzip-dev \
        libcurl4-openssl-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install zip \
    && docker-php-ext-install curl \
    && docker-php-ext-install odbc \
    && docker-php-ext-install pdo \
    && docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
    && docker-php-ext-install pdo_odbc \
    && docker-php-source delete \
    && apt-get purge -y --auto-remove


The docker build file contains a few instruction for the build, I will list only commands used above, but there are many commands available in docker build, for more information I would recommend you to refer docker documentation.

FROM : This is reference to base image from docker hub

COPY: Copy host directory in container at specified path, we will be copying everything installed at /var/www/html in host to same location in docker image. (for quick access I have made a copy of everything under /var/www/html to src/ directory where this Dockerfile is located)

RUN: This command runs a script in container in the build process.

We are using RUN command to update directory permissions and to install a few libraries required for PHP extensions along with actual PHP extensions.

Once we have Dockerfile all we need to do is run build command as follows to generate docker image :

docker build -t opencarthdb .

We will have a docker image at the end of build, we will push this docker image to docker hub repository as follows:

docker tag opencarthdb:latest <dockerhub_user>/<repository_name>:<tag>

docker push <dockerhub_user>/<repository_name>:<tag>

That’s it, we have successfully build OpenCart docker image to deploy on Docker Swarm cluster, refer above video for detailed instruction on Docker Swarm create, deploy and scale.

Next, we will deploy this docker image on Docker Swarm cluster using following command.

docker service create --name cart -p 80:80 --with-registry-auth --replicas 3 <dockerhub_user>/<repository>:<tag>

This will create docker service “cart” and deploy 3 instances of OpenCart on Docker Swarm cluster. We will be able to access cart on swarm hosts where these instance are active.

The cart instances can be scaled using following command:

docker service scale cart=12


In the end, we have different ways of using SAP HANA Express, we saw one possibility this series.


If you like this article, please feel free to share, tweet, like or follow me for new articles.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.