table of Contents
Details on how to use Docker Kong in the discussion can be in the presence of Kong found on the mirror DockerHub page. We also have a Docker Compose Template , built-in group and scalability.
With database schema
The following is a simple example showing how a container is connected to Cassandra kong or PostgreSQL.
- Create a docker network you need to manually create a network to discover and communicate with each other between the vessel. In this case, kong-net is the name of the network, you can easily change of name.
$ docker network create kong-net
- Run Database
Cassandra is desirable to use a container:
$ docker run -d --name kong-database \ --network=kong-net \ -p 9042:9042 \ cassandra:3
PostgreSQL is desirable to use a container:
$ docker run -d --name kong-database \
--network=kong-net \
-p 5432:5432 \
-e POSTGRES_USER=kong \
-e POSTGRES_DB=kong \
postgres:9.6
- Preparing the database with a temporary Kong container run the migration.
$ docker run --rm \
--network=kong-net \
-e KONG_DATABASE=postgres \
-e KONG_PG_HOST=kong-database \
-e KONG_CASSANDRA_CONTACT_POINTS=kong-database \
kong:latest kong migrations bootstrap
In the above example, Cassandra and PostgreSQL configuration have been completed, however, you need to use Cassandra update or PostgreSQL KONG_DATABASE
environment variables. Note for points below the 0.15 version: the version number is lower than 0.15 Kong (up to 0.14), with the up
replacement subcommand bootstrap
. In addition, the version number is lower than the ban kong 0.15 while running migration. The same time, only one node migration kong running. This limitation does not exist on kong version 0.15,1.0 or later. 1. Start After kong ready to migrate databases and running, start a connection to the database container kong container, like the earlier temporary migration container.
$ docker run -d --name kong \
--network=kong-net \
-e KONG_DATABASE=postgres \
-e KONG_PG_HOST=kong-database \
-e KONG_CASSANDRA_CONTACT_POINTS=kong-database \
-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, 0.0.0.0:8444 ssl \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong:latest
- Use kong
kong is running:
$ curl -i http://localhost:8001/
By 5 minutes Getting started quickly learn how to use kong.
No database schema
With no database schema start kong steps of:
- This network is created docker Like Pg / Cassandra tutorial. We use the same network name
kong-net
, you can also renamed the name you want.
$ docker network create kong-net
When you run with no database schema kong This step is not mandatory, however, in case you later want to add some other stuff (for example, by the driver of the speed limit Redis Cluster plug) is a good hint.
- Creating a docker disk (volume)
in this article, a docker physical disk is host of a directory that is mapped to a directory within the container. Disk has a name, in this, we will name itkong-vol
.
docker volume create kong-vol
Now, you can check that the disk:
$ docker volume inspect kong-vol
This result is similar:
[
{
"CreatedAt": "2019-05-28T12:40:09Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/kong-vol/_data",
"Name": "kong-vol",
"Options": {},
"Scope": "local"
}
]
Note that entry MountPoint
, the next step we will use this path.
- Prepare your configuration file
The syntax and related properties in the declarative configuration format presentation.
Add all the entries in the required (Services service, Route route, Plugins plugins, Consumers consumers, etc.).
For this tutorial, we assume you name it kong.yml
.
Save the file on a step-mentioned MountPoint
lower path. In the present embodiment, the storage path /var/lib/docker/volumes/kong-vol/_data/kong.yml
.
- No database schema to start kong
although canKONG_DATABASE=off
start in a non-kong database schema, but a more common way is byKONG_DECLARATIVE_CONFIG
variables declarative configuration files as parameters. To this end, we want this file is visible in the container. We-v
achieve operational, it will bekong-vol
mapped to the container/usr/local/kong/declarative
directory.
$ docker run -d --name kong \
--network=kong-net \
-v "kong-vol:/usr/local/kong/declarative" \
-e "KONG_DATABASE=off" \
-e "KONG_DECLARATIVE_CONFIG=/usr/local/kong/declarative/kong.yml" \
-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, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong:latest
- Use kong
Kong should have been up and running, including the entry kong.yml added.
$ curl -i http://localhost:8001/
For example, to obtain the list of services:
$ curl -i http://localhost:8001/services