Deploying Kong using Docker Compose

Posted by Fugui on May 3, 2023

Kong

In today’s world, APIs are an essential part of any software system. They enable software components to interact with each other, making it easier to build complex systems. Kong is a popular open-source API gateway that simplifies the process of managing APIs. In this blog post, we will explore how to deploy Kong using Docker Compose.

Setting up Kong

Docker Compose is a tool that simplifies the process of deploying multi-container Docker applications. Here is an example Docker Compose file for deploying Kong:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
version: '3'

services:

  kong-database:
    image: postgres:9.6
    container_name: kong-database
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=kong
      - POSTGRES_DB=kong
      - POSTGRES_PASSWORD=kong
    networks:
      - kong-net
    volumes:
      - "db-data-kong-postgres:/var/lib/postgresql/data"

  kong-migrations:
    image: kong
    environment:
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
      - KONG_PG_PASSWORD=kong
      - KONG_CASSANDRA_CONTACT_POINTS=kong-database
    command: kong migrations bootstrap
    restart: on-failure
    networks:
      - kong-net
    depends_on:
      - kong-database

  kong:
    image: kong:2.6.0-alpine
    container_name: kong
    environment:
      - LC_CTYPE=en_US.UTF-8
      - LC_ALL=en_US.UTF-8
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
      - KONG_PG_USER=kong
      - KONG_PG_PASSWORD=kong
      - KONG_CASSANDRA_CONTACT_POINTS=kong-database
      - KONG_PROXY_ACCESS_LOG=/dev/stdout
      - KONG_ADMIN_ACCESS_LOG=/dev/stdout
      - KONG_PROXY_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl
    restart: on-failure
    ports:
      - 8000:8000
      - 8443:8443
      - 8001:8001
      - 8444:8444
    links:
      - kong-database:kong-database
    networks:
      - kong-net
    depends_on:
      - kong-migrations

  konga:
    image: pantsel/konga
    ports:
      - 1337:1337
    links:
      - kong:kong
    container_name: konga
    environment:
      - NODE_ENV=production

volumes:
  db-data-kong-postgres:

networks:
  kong-net:
    external: false

Kong commands

1
2
3
4
kong restart -c /etc/kong/kong.conf
kong migrations bootstrap -c /etc/kong/kong.conf
kong start -c /etc/kong/kong.conf --vv
kong stop

— Fugui,Data engineer、Machine learning Engineer、Software Engineer.