Creating a local development environment to Kong API with Docker
Tags: docker, kong
Published: 2021-09-11 15:27:29

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7ncx99khx1i2dhk1tvp.png)
In this article let’s create a local development environment for Kong API. This environment is very useful to test our integration between our applications and Kong API Gateway.

> If you want to know more about Kong API Management, [**check its documentation**](https://konghq.com/kong). Beyond API Gateway, Kong has other nice features to management our APIs.

We are going to use Docker to create our local development environment. Then, please install [**_Docker tools_**](https://www.docker.com/) in your local machine if you don’t have them yet.

Three docker containers are required to create a local development environment:

*   [**_pantsel/konga_**](https://hub.docker.com/r/pantsel/konga/): open source admin tool for Kong API Management.
*   [**_kong_**](https://hub.docker.com/_/kong): Kong API Management
*   [**_postgres_**](https://hub.docker.com/_/postgres): Database for Kong API Management

#### Running Kong API Gateway

First, let’s create a docker network to each initiate docker container can communicate between themselves:

{% gist https://gist.github.com/luis-alexandre/07dcaed0e8f795db2328b3a78b4ba401 %}

Start Postgres database to create a database for Kong API:

{% gist https://gist.github.com/luis-alexandre/f03557106bc706f267348233992951c2 %}

> In this example we are using Postgres to creating a new database, however, Kong API Gateway supports **Cassandra** as its database as well.

Now, we need to run a data migration process to prepare Kong API database. Run the command below to start the data migration process:

{% gist https://gist.github.com/luis-alexandre/2045a697ffa9dd0481bc2b25de2c6b7b %}

Finally, start Kong API Gateway with the command below:

{% gist https://gist.github.com/luis-alexandre/e308018e5d9935a4bf3361a1dc430f85 %}

When the container is ready, two ports will be available for use in our machine (**localhost)**:

*   _Admin API \[_[_http://localhost:8001_](http://localhost:8001)_\]:_ Use this port to manage your APIs in Kong API Gateway.
*   _Proxy \[_[_http://localhost:8000_](http://localhost:8000)_\]:_ Use this port to call your APIs with Kong API Gateway.

> Check [**Admin API documentation**](https://docs.konghq.com/gateway-oss/2.5.x/admin-api/) to know more about how to manage your APIs in Kong API Gateway.

#### Running Admin UI

Now that we have our Kong API Gateway ready, we can manage services, routes, and plugins for our APIs.

Those Kong API objects are managed with Admin API. For instance, the command below creates a new service to fictional _“Product API”_ from the fictional address _“https://product-api.net”_:

{% gist https://gist.github.com/luis-alexandre/b05aeb54167d8f2bc65534f0ce236d7c %}

Sometimes, this task can be very challenging. Then, for testing purposes, we can manage our APIs in Kong API Gateway with [**_Konga_**](https://github.com/pantsel/konga):

{% gist https://gist.github.com/luis-alexandre/cb4ffb49c2a2eb549bf674ae2ca2cf31 %}

> Konga is an open source project that allows us to manage Kong API Gateway with a UI. You can know more about the [**project here**](https://github.com/pantsel/konga).

Run the command below to start the Konga container:

Konga will be started on port 1337 from your localhost. In the first access, the application will request to create a new user.

After creating the user, we need to create a new connection between Konga and Kong API Admin to manage our services:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98wkua0xdnanb61a4skg.png)

Provide a name for the new connection, the IP address where Kong Admin API is running, and click on the _“Create Connection”_ button. Then, you can see the Konga Dashboard.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xh5ip7zqo7v4j0e3n8v.png)

If you had some issue with Kong Admin URL, try to provide the IP address from the Kong docker container. Execute the command below to get the IP address from the container:

{% gist https://gist.github.com/luis-alexandre/89937cafa0f09dc0f4630e3aecd1ff59 %}

It’s done! Now you can explore more Kong API Gateway in your local machine. Have happy findings with Kong API Gateway! :D

I hope that this can be helpful for you!