How to install Kong Gateway on docker
Kong Gateway is a lightweight, fast, and flexible cloud-native API gateway. Kong is a reverse proxy that lets you manage, configure, and route requests.
This guide provides steps to configure Kong Gateway on Docker with or without a database. The database used in this guide is PostgreSQL.
Install Kong Gateway with a database.
Set up a Kong Gateway container with a PostgreSQL database to store Kong configuration.
Step 1. Create a custom Docker network.
A custom docker network allows the containers to discover and communicate with each other.
docker network create kong-net
You can name this network anything you want. We use kong-net
this as an example throughout this guide.
Step 2. Start a PostgreSQL container.
docker run -d --name kong-database \
--network=kong-net \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
-e "POSTGRES_PASSWORD=kongpass" \
postgres:13
In our example, we use the default value “kong” for variables POSTGRES_USER and POSTGRES_DB
. In the variable POSTGRES_PASSWORD, we can use any string. Our PostgreSQL container is named “kong-database”, and it can communicate with any container on the “kong-net” network.
Step 3. Prepare the Kong database.
docker run --rm --network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_PASSWORD=kongpass" \
-e "KONG_PASSWORD=test" \
kong/kong-gateway:3.7.1.2 kong migrations bootstrap
Where:
- KONG_DATABASE specifies the type of database that Kong is using.
- KONG_PG_HOST – the name of the PostgreSQL docker container communicating over the “kong-net” network from the previous step.
- KONG_PG_PASSWORD – the password you set when bringing up the PostgreSQL container in the previous step.
- KONG_PASSWORD – the default password for the admin super user for Kong Gateway, which is used only for the enterprise.
Step 4. Start Kong Gateway
Run the following command to start a container with Kong Gateway
Important: Don’t use the “admin_listen” setting to listen for requests from any source in the production environment.
docker run -d --name kong-gateway \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kongpass" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \
-e "KONG_ADMIN_GUI_URL=http://localhost:8002" \
-e KONG_LICENSE_DATA \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
-p 8002:8002 \
-p 8445:8445 \
-p 8003:8003 \
-p 8004:8004 \
kong/kong-gateway:3.7.1.2
Where:
- — name and –network – the name of the container to create and the Docker network it communicates on.
- KONG_DATABASE – specifies the type of database that Kong Gateway is using.
- KONG_PG_HOST – the name of the PostgreSQL docker container communicating over the “kong-net” network.
- KONG_PG_USER and KONG_PG_PASSWORD – the PostgreSQL username and password. Kong Gateway needs the login information to store configuration data in the KONG_PG_HOST database.
- All _LOG parameters – set file paths for the logs to output to or use the values in the example to print messages and errors to stdout and stderr.
KONG_ADMIN_LISTEN – the port that the Kong Admin API listens on for requests.
KONG_ADMIN_GUI_URL – The URL for accessing Kong Manager, preceded by a protocol (for example, http://).
KONG_LICENSE_DATA – (Enterprise only) If you have a license file and have saved it as an environment variable, this parameter pulls the license from your environment.
Now we need to verify our installation via accessing the /services endpoint using the Admin API
curl -i -X GET --url http://localhost:8001/services
You should receive a 200
status code.
Now we can verify that Kong Manager is running by accessing it using the URL specified in KONG_ADMIN_GUI_URL
http://localhost:8002

Source: