Running Apigee Edge Microgateway in a Docker Container

ndietz

Apr 28, 2016

It’s not uncommon to run a Node.js app in a Docker container and, in fact, it’s a great way to run your apps in isolation with their own environments. And, like other Node.js applications, Apigee Edge Microgateway (MGW) can be run in a Docker container!

To get started, you should have MGW 2.0.0 ready to go. Docker should be installed locally on your machine. We’ll start by configuring your MGW setup and attaining the required credentials for start up. Then we’ll test the MGW instance running in the Docker container.

To start, configure your MGW instance with the following command from the project’s root directory:

The output will include important information about your configuration, including its location on your system:

saving configuration information to:

~/.edgemicro/<org>-<env>-config.yaml

It’ll also include your configuration’s credentials required for start up:

The following credentials are required to start edge micro key:

0c4449144dc894f68913a7385dbae92f64df915ce2e76a2ff45cbdb5fb3581

secret:

75a10ceb40bd31068ae4a334198566e1f0a4f3f84536100e935b9e85fbfa

Now, save these credentials and some of your configuration info for start up. In the directory of your choosing, create a file named <org>-<env>-env.list and put the following information in this format:

EDGEMICRO_KEY=0c4449144dc894f68913a7385dbae92f64df9157ce2e76a2ff45cbd

EDGEMICRO_SECRET=75a10ceb40bd31068ae54a334198566e1f0a4f3fd845361a

EDGEMICRO_ORG=<org>

EDGEMICRO_ENV=<env>

It’s important to use these environment variable names, as they are required for MGW to start.

So, you have MGW configured and the start up credentials saved. Now, you can start using Docker. Start up your local Docker installation and pull down the image from the Docker hub using the following command:

docker pull ndietz/emgw

This image has MGW installed on it and is merely waiting for a configuration and key/secret pair to start running. You’ll share your new MGW configuration via a shared volume in the run command and pass our credentials via the environment variable list file we made earlier. So, using the directory of the aforementioned configuration location and the environment variable list file, run the following command:

Next, confirm that the container started properly by running the following command:

docker ps

This should show your container running with the command “npm start.” Test MGW by hitting it with a cURL request, which, on different machines, might require you to use the docker-machine’s given IP address rather than localhost.

For example, on OS X using docker-machine in terminal:

curl -i $(docker-machine ip)”:8000/myapi”

Now you have Apigee Edge Microgateway running in a Docker container! If you’d like to run multiple different MGW configurations simultaneously, change the org/env and key/secret information to match your other configurations and change the exposed port on your host machine so as to not conflict with your already-running containers.