WSO2 API Microgateway has a runtime Docker image in which you can provide executable runtime artifacts as a mount. Let's follow the instructions below to see how we can create Docker image by including the runtime executable artifacts, so that you do not have to mount the artifacts from outside. This approach uses the
deployment-config.toml file as an input to the WSO2 API Microgateway Toolkit, which generates the Docker images from the WSO2 API Microgateway base image by including all the API runtime artifacts as well.
Let's deploy WSO2 API Microgateway in Docker.
Step 1 - Follow the installation prerequisites
Make sure to install and set up Docker and the installation prerequisites for the Microgateway Toolkit.
Step 2 - Create a microgateway project
- Navigate to a preferred workspace folder using the command line to set the location that is used to store the Microgateway project.
Create a project.
Let's create a project named "petstore" by running the following command. This will create the folder structure for the artifacts to be included.
Step 3 - Build the microgateway project
Add the API to the project.
Navigate to the
/petstore/api_definitionsdirectory and add the OpenAPI definition(s) to this directory. Let's use the Petstore sample OpenAPI definition in this scenario.
Create the input for WSO2 API Microgateway Toolkit.
Create a file named
deployment.tomlin a preferred location.This TOML file should contain the relevant deployment configurations (e.g., Docker image name, registry, tag, etc.) as shown below. For more information on each of the above parameters, see deployment.toml for Docker. Note that you will have to use this TOML file as the input, by way of passing the file path, when creating the Microgateway project.
Specify docker credentials
If the docker image push is enabled to push the image to a docker registry , specifying of the username and password should be done using environment variables
export DOCKER_PASSWORD =<PASSWORD>
Build the microgateway project.
Use your command line tool to navigate to where the project directory ("petstore") was created and execute the following command to build the project.
The Docker image is created in your local registry and you can use it to spawn a WSO2 API Microgateway Docker container.
Step 4 - Run the Docker container
Run the Docker container using the following command.
When following this Docker deployment guide, you will end up by creating a Docker image with APIs built into it; thereby, the
.balx file will already be inside the Docker image. Therefore, unlike in the Quick Start Guide for Docker you do not have to specify the project name when running the Docker container and mount the
.balx file in to the Docker image.
If you are working in a Linux environment, you can either use the above command or the following command to start your Docker container. In the following command the Docker container uses the host network driver for your container.
Step 5 - Invoke the sample API
Step 5.1 - Obtain token
After the APIs are exposed via WSO2 API Microgateway, you can invoke an API with a valid JWT token or an opaque access token.
In order to use JWT tokens, WSO2 API Microgateway should be presented with a JWT signed by a trusted OAuth2 service.
Let's use the following sample JWT token that never expires, which was generated using WSO2 API Manager for testing purposes.
Step 5.2 - Invoke the API
Invoke the API using the JWT token using the following command.
Retrieve the Docker container IP address.
Execute the command below to set a self-contained OAuth2.0 access token in the JWT format as a variable on your terminal session.
When you are deploying the Microgateway in production, make sure to change its default certificates.
You can now invoke the API running on the Microgateway using the following cURL command.