Kong install by Docker Chinese translation

View original

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.

  1. 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
  1. 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
  1. 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_DATABASEenvironment variables. Note for points below the 0.15 version: the version number is lower than 0.15 Kong (up to 0.14), with the upreplacement 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
  1. 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:

  1. 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.

  1. 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 it kong-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.

  1. 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 MountPointlower path. In the present embodiment, the storage path /var/lib/docker/volumes/kong-vol/_data/kong.yml.

  1. No database schema to start kong
    although can KONG_DATABASE=offstart in a non-kong database schema, but a more common way is by KONG_DECLARATIVE_CONFIGvariables declarative configuration files as parameters. To this end, we want this file is visible in the container. We -vachieve operational, it will be kong-volmapped to the container /usr/local/kong/declarativedirectory.
 $ 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
  1. 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

Guess you like

Origin www.cnblogs.com/dogify/p/11972091.html