11436 SSO

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:

./cli/edgemicro configure -o <organization> -e <environment> -u <Apigee account>

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:

docker run --env-file ./<org>-<env>-env.list  -p 8000:8000 -v <directory containing configuration>:/root/.edgemicro -d -t ndietz/emgw

Let’s break this down:

--env-file ./<org>-<env>-env.list places the environment variables from your list into the container’s environment.

-p 8000:8000 maps the port on the host machine (the first parameter) to the exposed port on the container (the second parameter).

-v <directory containing configuration>:/root/.edgemicro mounts the directory containing your configuration on the host machine (first parameter) to the specified directory in the container (second parameter).

-d runs in the container in detached mode and -t specifies the tag of the image you want to run.

These options are all documented on the Docker reference page.

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.

Please engage with us on the Apigee Community  (https://community.apigee.com/spaces/71/index.html) if you have any questions or run into any issues when you try this out.

Microservices Done Right

Next Steps

 
 

Resources Gallery

News