Microgateway Docker Based provisioning
Tags: microgateway, docker, api, tutorial
Published: 2021-08-12 13:22:14

---
title: Microgateway Docker Based provisioning
published: true
date: 2021-05-28 10:48:48 UTC
tags: #microgateway, #docker, #api, #tutorial 
canonical_url: https://tech.forums.softwareag.com/t/microgateway-docker-based-provisioning/241713
---

## Introduction

Microgateway is a lightweight, distributed API proxy designed to enforce policies and business logic near the service end point. Microgateway runs with its own JRE. It contains assets such as API, application, policy, and alias definitions. Microgateway can be controlled using simple command line interface using start and stop commands. Microgateway contains a service for enforcing policy on REST API. Microgateway exposes REST APIs for querying status, system settings, and provisioned assets. Microgateway provides complete control over the landscape by facilitating enforcement of policies such as authentication, traffic monitoring and management.

This article explains how to provision Microgateways. This article covers Docker-based Microgateway provisioning, from existing API Gateway installation and using docker hub image.

## Audience

It is assumed that readers of this article are familiar with usage of API Gateway, Microgateway and Docker basics.

## Pre-Requisites

- Start API Gateway
- Configure few APIs
- Export of APIs and related assets from the API Gateway

## Use Case

The common usage of microservices and architectures based on microservices has increased the need for light weight gateways. The flexible deployment nature of Microgateway makes it ideal for low latency small footprint solutions.

Microgateway enables microservices to communicate with each other directly without the need for API Gateway. This eases the traffic overload on API Gateway and reduces the latency in the communication round trip. The required protection policies can be enforced on the Microgateway to establish a secure communication channel between the microservices.

![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/6/618e0cb97369e756e96dcc77ad466a85d6a5b865.png)

## Docker-based provisioning

Microgateway official docker image can be downloaded from docker hub and can be used for Microgateway provisioning. This article explains the steps required for creating a Microgateway image from an existing Microgateway installation and by using Microgateway official docker image. Microgateway package contains all the essential artifacts required for running a microgateway.

The contents of Microgateway zip are

- JRE
- Microgateway server
- Microgateway CLI
- Configuration files
- One or more exported API Gateway asset archives

### Creating Microgateway instance using Docker Hub image

This method uses Software AG official docker image of Microgateway.

### Steps:

1. Login to docker hub and sign up for Software AG Microgateway Trial image using the below link
[https://hub.docker.com/\_/softwareag-microgateway-trial](https://hub.docker.com/_/softwareag-microgateway-trial)
2. Pull the microgateway image using the below command
`docker pull store/softwareag/microgateway-trial:10.5`
3. Start Microgateway container using the below command
```
docker run -p 9090:4485 \ --env mcgw_api_gateway_url=http://sample.com:5555/rest/apigateway \ --env mcgw_api_gateway_user=Administrator \ --env mcgw_api_gateway_password=password \ --env mcgw_downloads_apis=petstore \ --name microgateway store/softwareag/microgateway-trial:10.5`
If Microgateway and API Gateway is running on the same machine then use --add-host=“myComputerName:myComputerIP” along with the docker run.
```
```
docker run -p 9090:4485 \
--add-host="myComputerName:myComputerIP" \ --env mcgw_api_gateway_url=http://sample.com:5555/rest/apigateway \ --env mcgw_api_gateway_user=Administrator \ --env mcgw_api_gateway_password=password \ --env mcgw_downloads_apis=petstore \ --name microgateway store/softwareag/microgateway-trial:10.5
```
4. Below APIs can be used to verify the status of Microgateway  
[http://localhost:9090/rest/microgateway/status](http://localhost:9090/rest/microgateway/status)  
[http://localhost:9090/rest/microgateway/assets](http://localhost:9090/rest/microgateway/assets)

## Microgateway Docker provisioning from existing API Gateway

Below options can be used to create Microgateway Docker image from existing API Gateway installation.

## Docker providing with asset archive from API Gateway

In this method all the configuration details are copied from API Gateway. There is not much flexibility for the user to modify the settings.

### Steps:

1. Navigate to the Microgateway installation directory
`<<Installation Dir>>\Microgateway`
2. Create an export of API from API Gateway and name the file apigw-archive.zip
3. Run the below docker command to create docker file
`.\microgateway.bat createDockerFile --docker_dir . -p 9090 -a apigw-archive.zip`
4. Run the below command to create a docker image
`docker build -f Microgateway_DockerFile -t sag:mcgw-static .`
5. Run docker images to verify if the image is created
`docker images`
6. Run the below command to start Microgateway container
```
docker run -d -p 9090:9090 \

--env mcgw_api_gateway_url=http://samplehost:port/rest/apigateway \
--env mcgw_api_gateway_user=Administrator \

--env mcgw_api_gateway_password=password \

--name mcgw-static sag:mcgw-static

```
7. Below APIs can be used to verify the status of Microgateway
[_http://localhost:9090/rest/microgateway/status_](http://localhost:9090/rest/microgateway/status)
[_http://localhost:9090/rest/microgateway/assets_](http://localhost:9090/rest/microgateway/assets)

### Creating Microgateway instance using yml file

This method uses yml file to create a docker image of Microgateway.

### Steps:

1. Create the custom-settings.yml file using the below command  
`microgateway.bat downloadSettings -gw http://host:port/rest/apigateway -gwu Administrator -gwp password –-output my-custom-settings.yml`
2. Edit the yml file to add ports, API Gateway details, Microgateway pool details and archive details (archive created manually from API Gateway).
```
ports:
   http: "8054"
   https: "8053" 
api_gateway:
   url: "localhost:ISPort"
   user: "Administrator"
   password: “password"
microgatewayPool:
    microgatewayPoolName: "DemoPool"
    microgatewayPoolDescription: "This is a Demo Pool"
archive:
   file: apigw-archive.zip
```
Since the archive is created manually from API Gateway all associated assets are also pulled from the Gateway.
3. Run the below command to create docker file  
`.\microgateway.bat createDockerFile --docker_dir . -c my-custom-settings.yml`
4. Run the below command to build the docker image  
`docker build -t sag:mcgw-dynamic -f Microgateway_DockerFile .`
5. Run the below command to start the docker container  
`docker run -d -p 9090:9090 --name mcgw-dynamic sag:mcgw-dynamic`
6. Below APIs can be used to verify the status of Microgateway  
[http://localhost:9090/rest/microgateway/status](http://localhost:9090/rest/microgateway/status)  
[http://localhost:9090/rest/microgateway/assets](http://localhost:9090/rest/microgateway/assets)

## API to invoke Microgateway APIs:

1. Microgateway APIs can be invoked using URL  
[http://localhost:microgatewayPort/gateway/petstore/1/pet/findByStatus](http://localhost:microgatewayPort/gateway/petstore/1/pet/findByStatus)

[Read full topic](https://tech.forums.softwareag.com/t/microgateway-docker-based-provisioning/241713)