Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
example docker-compose.yml for kong, postgres and konga
version: "3"
networks:
kong-net:
driver: bridge
services:
#######################################
# Postgres: The database used by Kong
#######################################
kong-database:
image: postgres:9.6
restart: always
networks:
- kong-net
environment:
POSTGRES_USER: kong
POSTGRES_DB: kong
ports:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "kong"]
interval: 5s
timeout: 5s
retries: 5
#######################################
# Kong database migration
#######################################
kong-migration:
image: kong:latest
command: "kong migrations bootstrap"
networks:
- kong-net
restart: on-failure
environment:
KONG_PG_HOST: kong-database
links:
- kong-database
depends_on:
- kong-database
#######################################
# Kong: The API Gateway
#######################################
kong:
image: kong:latest
restart: always
networks:
- kong-net
environment:
KONG_PG_HOST: kong-database
KONG_PROXY_LISTEN: 0.0.0.0:8000
KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443
KONG_ADMIN_LISTEN: 0.0.0.0:8001
depends_on:
- kong-migration
- kong-database
healthcheck:
test: ["CMD", "curl", "-f", "http://kong:8001"]
interval: 5s
timeout: 2s
retries: 15
ports:
- "8001:8001"
- "8000:8000"
#######################################
# Konga database prepare
#######################################
konga-prepare:
image: pantsel/konga:next
command: "-c prepare -a postgres -u postgresql://kong@kong-database:5432/konga_db"
networks:
- kong-net
restart: on-failure
links:
- kong-database
depends_on:
- kong-database
#######################################
# Konga: Kong GUI
#######################################
konga:
image: pantsel/konga:next
restart: always
networks:
- kong-net
environment:
DB_ADAPTER: postgres
DB_HOST: kong-database
DB_USER: kong
TOKEN_SECRET: km1GUr4RkcQD7DewhJPNXrCuZwcKmqjb
DB_DATABASE: konga_db
NODE_ENV: production
depends_on:
- kong-database
ports:
- "1337:1337"
@lokeshsuhas

This comment has been minimized.

Copy link

@lokeshsuhas lokeshsuhas commented Feb 28, 2019

Error creating a connection to Postgresql using the following settings:

@rjpalermo1

This comment has been minimized.

Copy link

@rjpalermo1 rjpalermo1 commented Mar 1, 2019

yup

kong_kong-database_1    docker-entrypoint.sh postgres    Up (healthy)   0.0.0.0:5432->5432/tcp
kong_kong-migration_1   /docker-entrypoint.sh kong ...   Restarting                           
kong_kong_1             /docker-entrypoint.sh kong ...   Restarting                           
kong_konga-prepare_1    /app/start.sh -c prepare - ...   Exit 0                               
kong_konga_1            /app/start.sh                    Up             0.0.0.0:1337->1337/tcp
@juarrosluis

This comment has been minimized.

Copy link

@juarrosluis juarrosluis commented Mar 9, 2019

Be careful on command: "kong migrations up"
Note for Kong < 0.15: with Kong versions below 0.15 (up to 0.14), use the up sub-command instead of bootstrap. Also note that with Kong < 0.15, migrations should never be run concurrently; only one Kong node should be performing migrations at a time. This limitation is lifted for Kong 0.15, 1.0, and above.

@shubhamoli

This comment has been minimized.

Copy link

@shubhamoli shubhamoli commented Mar 20, 2019

Two fixes which worked for me.

Env:
OS - Amazon linux
Kong images version - latest

  1. kong migrations up >> kong migrations bootstrap . (newer versions of kong as mentioned by @juarrosluis)
  2. In the section where you define your kong service and under environment key, add KONG_DATABASE: postgres alongwith KONG_PG_HOST.
@iwanskit

This comment has been minimized.

Copy link

@iwanskit iwanskit commented Apr 16, 2019

@shubhamoli I've tried to change kong migrations up to kong migrations bootstrap
but this is what I've get on kong-migration: No such command for migrations: bootstrap :(

@rakehell1986

This comment has been minimized.

Copy link

@rakehell1986 rakehell1986 commented Jul 11, 2019

`
[root@smartagent-VODC sat-docker]# vi docker-compose.yml

image: cogniteev/echo
container_name: sat_db_data
command: echo 'Data Container for PostgreSQL'
volumes:
  - pg-data:/var/lib/postgresql/data

sat_kong:
build: ./kong
container_name: kong
command: "kong migrations bootstrap"
environment:
- KONG_DATABASE=postgres
- KONG_PG_HOST=sat_db
- KONG_CASSANDRA_CONTACT_POINTS=sat_db
- KONG_PG_PASSWORD=*******
- 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
ports:
- "8000:8000/tcp"
- "8001:8001/tcp"
- "8443:8443/tcp"
- "8444:8444/tcp"
depends_on:
- sat_db
restart: on-failure
links:
- sat_db

sat_konga:
image: pantsel/konga
container_name: konga
command: "-c prepare -a postgres -u postgresql://konga:@sat_db:5432/konga"
restart: on-failure
environment:
- TOKEN_SECRET=km1GUr4RkcQD7DewhJPNXrCuZwcKmqjb
- DB_ADAPTER=postgres
- DB_HOST=sat_db
- DB_PORT=5432
- DB_USER=konga
- DB_PASSWORD=

- DB_DATABASE=konga
- DB_PG_SCHEMA=public
- NODE_ENV=production
depends_on:
- sat_db
- sat_kong
ports:
- "1337:1337"
links:
- sat_db
- sat_kong`

@rakehell1986

This comment has been minimized.

Copy link

@rakehell1986 rakehell1986 commented Jul 11, 2019

Hi please take the below configuration. it's always cant reach to success point.

kong /konga container are not up.

@gabrielmancini

This comment has been minimized.

Copy link

@gabrielmancini gabrielmancini commented Nov 29, 2019

+1

@ALTELMA

This comment has been minimized.

Copy link

@ALTELMA ALTELMA commented Feb 29, 2020

`
[root@smartagent-VODC sat-docker]# vi docker-compose.yml

image: cogniteev/echo
container_name: sat_db_data
command: echo 'Data Container for PostgreSQL'
volumes:
  - pg-data:/var/lib/postgresql/data

sat_kong:
build: ./kong
container_name: kong
command: "kong migrations bootstrap"
environment:

  • KONG_DATABASE=postgres
  • KONG_PG_HOST=sat_db
  • KONG_CASSANDRA_CONTACT_POINTS=sat_db
  • KONG_PG_PASSWORD=*******
  • 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
    ports:
  • "8000:8000/tcp"
  • "8001:8001/tcp"
  • "8443:8443/tcp"
  • "8444:8444/tcp"
    depends_on:
  • sat_db
    restart: on-failure
    links:
  • sat_db

sat_konga:
image: pantsel/konga
container_name: konga
command: "-c prepare -a postgres -u postgresql://konga:@sat_db:5432/konga" restart: on-failure environment: - TOKEN_SECRET=km1GUr4RkcQD7DewhJPNXrCuZwcKmqjb - DB_ADAPTER=postgres - DB_HOST=sat_db - DB_PORT=5432 - DB_USER=konga - DB_PASSWORD=

  • DB_DATABASE=konga
  • DB_PG_SCHEMA=public
  • NODE_ENV=production
    depends_on:
  • sat_db
  • sat_kong
    ports:
  • "1337:1337"
    links:
  • sat_db
  • sat_kong`

+1
Let's confirm with this or Need to add
DB_PASSWORD=

Because postgres always require DB_PASSWORD

@baxiang

This comment has been minimized.

Copy link

@baxiang baxiang commented Mar 3, 2020

     version: "3.7"

volumes:
  kong_data: {}
  
networks:
 kong-net:

services:

  #######################################
  # Postgres: The database used by Kong
  #######################################
  kong-database:
    image: postgres:9.6
    container_name: kong-postgres
    restart: on-failure
    networks:
      - kong-net
    volumes:
      - kong_data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: kong
      POSTGRES_PASSWORD: ${KONG_PG_PASSWORD:-kong}
      POSTGRES_DB: kong
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "kong"]
      interval: 30s
      timeout: 30s
      retries: 3

  #######################################
  # Kong database migration
  #######################################
  kong-migration:
    image: ${KONG_DOCKER_TAG:-kong:latest}
    command: kong migrations bootstrap
    networks:
      - kong-net
    restart: on-failure
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-database
      KONG_PG_DATABASE: kong
      KONG_PG_USER: kong
      KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
    depends_on:
      - kong-database

  #######################################
  # Kong: The API Gateway
  #######################################
  kong:
    image: ${KONG_DOCKER_TAG:-kong:latest}
    restart: on-failure
    networks:
      - kong-net
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-database
      KONG_PG_DATABASE: kong
      KONG_PG_USER: kong
      KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
      KONG_PROXY_LISTEN: 0.0.0.0:8000
      KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443
      KONG_ADMIN_LISTEN: 0.0.0.0:8001
    depends_on:
      - kong-database
    healthcheck:
      test: ["CMD", "kong", "health"]
      interval: 10s
      timeout: 10s
      retries: 10
    ports:
      - "8000:8000"
      - "8001:8001"
      - "8443:8443"
      - "8444:8444"

  #######################################
  # Konga database prepare
  #######################################
  konga-prepare:
    image: pantsel/konga:latest
    command: "-c prepare -a postgres -u postgresql://kong:${KONG_PG_PASSWORD:-kong}@kong-database:5432/konga"
    networks:
      - kong-net
    restart: on-failure
    depends_on:
      - kong-database

  #######################################
  # Konga: Kong GUI
  #######################################
  konga:
    image: pantsel/konga:latest
    restart: always
    networks:
        - kong-net   
    environment:
      DB_ADAPTER: postgres
      DB_URI: postgresql://kong:${KONG_PG_PASSWORD:-kong}@kong-database:5432/konga
      NODE_ENV: production
    depends_on:
      - kong-database
    ports:
      - "1337:1337"

@ALTELMA

This comment has been minimized.

Copy link

@ALTELMA ALTELMA commented Mar 5, 2020

@baxiang
This one can fix konga db lost when re-run docker-compose, right?
Now I still facing with this issue.

@LincWong

This comment has been minimized.

Copy link

@LincWong LincWong commented Mar 12, 2020

I have a issue from postgres:

Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html

fixed by:

POSTGRES_HOST_AUTH_METHOD: trust
@duong20165929

This comment has been minimized.

Copy link

@duong20165929 duong20165929 commented Mar 16, 2020

@baxiang could u send me file docker-compose.yml. I used that file but have erro. Thank u

@baxiang

This comment has been minimized.

Copy link

@baxiang baxiang commented Mar 16, 2020

@baxiang could u send me file docker-compose.yml. I used that file but have erro. Thank u
@duong20165929
docker-compose.yml
what error ?

@duong20165929

This comment has been minimized.

Copy link

@duong20165929 duong20165929 commented Mar 16, 2020

@baxiang my docker-compose version is too old. so i updated the newest version and i runned.
Thank u so much for supporting me

@ALTELMA

This comment has been minimized.

Copy link

@ALTELMA ALTELMA commented Apr 28, 2020

@duong20165929 How do you change? Now I still facing migration not run because of Postgres password not correct.

@duong20165929

This comment has been minimized.

Copy link

@duong20165929 duong20165929 commented Apr 28, 2020

don't care about that. Because its normal error. u should install p4admin for postgre.

@ALTELMA

This comment has been minimized.

Copy link

@ALTELMA ALTELMA commented Apr 28, 2020

If anyone still facing a problem cannot start kong Gateway API.
Please to change command in migration

kong migration up

However, please check docker logs name_of_container --follow to see what errors you got.

@lonnietc

This comment has been minimized.

Copy link

@lonnietc lonnietc commented May 10, 2020

Hello All,

Pretty new to Kong & Konga.

How hard would it be to have this docker-compose file add a Letsencrypt container to spin up as well?

I would like to have SSL encryption for the Kong public facing port (which could be set to 443) as well as the the Konga UI on port 1337.

Any help would be greatly appreciate.
Cheers,

@BogdanDarius

This comment has been minimized.

Copy link

@BogdanDarius BogdanDarius commented Jul 8, 2020

Hello All,

Pretty new to Kong & Konga.

How hard would it be to have this docker-compose file add a Letsencrypt container to spin up as well?

I would like to have SSL encryption for the Kong public facing port (which could be set to 443) as well as the the Konga UI on port 1337.

Any help would be greatly appreciate.
Cheers,

You could use a kong plugin to get SSL encryption.
https://github.com/Kong/kong-plugin-acme

@lonnietc

This comment has been minimized.

Copy link

@lonnietc lonnietc commented Jul 8, 2020

@venkibale

This comment has been minimized.

Copy link

@venkibale venkibale commented Aug 26, 2020

Hi,

I am new to kong, anyone have experience in deploying kong setup to Kubernetes, If so can anybody share their yaml file?

Thanks in advance.

@alexted

This comment has been minimized.

Copy link

@alexted alexted commented Sep 13, 2020

It doesn't work with latest version of PostgreSQL. I have an issue:
2020-09-13 09:49:57.837 UTC [593] ERROR: column r.consrc does not exist at character 212
2020-09-13 09:49:57.837 UTC [593] HINT: Perhaps you meant to reference the column "r.conkey" or the column "r.conbin".
2020-09-13 09:49:57.837 UTC [593] STATEMENT: SELECT x.nspname || '.' || x.relname as "Table", x.attnum as "#", x.attname as "Column", x."Type", case x.attnotnull when true then 'NOT NULL' else '' end as "NULL", r.conname as "Constraint", r.contype as "C", r.consrc, fn.nspname || '.' || f.relname as "F Key", d.adsrc as "Default" FROM (SELECT c.oid, a.attrelid, a.attnum, n.nspname, c.relname, a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod) as "Type", a.attnotnull FROM pg_catalog.pg_attribute a, pg_namespace n, pg_class c WHERE a.attnum > 0 AND NOT a.attisdropped AND a.attrelid = c.oid and c.relkind not in ('S','v') and c.relnamespace = n.oid and n.nspname not in ('pg_catalog','pg_toast','information_schema')) x left join pg_attrdef d on d.adrelid = x.attrelid and d.adnum = x.attnum left join pg_constraint r on r.conrelid = x.oid and r.conkey[1] = x.attnum left join pg_class f on r.confrelid = f.oid left join pg_namespace fn on f.relnamespace = fn.oid where x.relname = 'konga_netdata_connections' and x.nspname = 'public' order by 1,2;

How to solve this problem?

@mvillafuertem

This comment has been minimized.

Copy link

@mvillafuertem mvillafuertem commented Nov 23, 2020

Hi @baxiang,

I am new to kong, I'm trying enable go_plugins, but I get this error. Any hint?

This is my kong.conf

plugins = bundled,go-hello
go_pluginserver_exe = /usr/local/bin/go-pluginserver
go_plugins_dir = /usr/local/kong/go_plugins/ 

I'm using this docker-compose https://github.com/baxiang/docker_compose/blob/master/kong/docker-compose.yml

Thanks in advance.

kong              | sh: /usr/local/bin/go-pluginserver: not found
kong              | 2020/11/23 11:08:22 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/MessagePack.lua:813: missing bytes
kong              | stack traceback:
kong              | 	[C]: in function 'error'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:813: in function 'underflow'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:529: in function 'unpack_cursor'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:843: in function 'unpack'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:463: in function 'get_plugin_info'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:472: in function 'get_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:519: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:159: in function 'load_plugin_handler'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:243: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:295: in function 'load_plugin_schemas'
kong              | 	/usr/local/share/lua/5.1/kong/init.lua:467: in function 'init'
kong              | 	init_by_lua:3: in main chunk
kong              | nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/MessagePack.lua:813: missing bytes
kong              | stack traceback:
kong              | 	[C]: in function 'error'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:813: in function 'underflow'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:529: in function 'unpack_cursor'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:843: in function 'unpack'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:463: in function 'get_plugin_info'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:472: in function 'get_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:519: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:159: in function 'load_plugin_handler'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:243: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:295: in function 'load_plugin_schemas'
kong              | 	/usr/local/share/lua/5.1/kong/init.lua:467: in function 'init'
kong              | 	init_by_lua:3: in main chunk
@baxiang

This comment has been minimized.

Copy link

@baxiang baxiang commented Nov 24, 2020

@mvillafuertem about go_plugins dockerfile

FROM kong/go-plugin-tool:latest-centos-7 as builder
ENV GOPROXY https://goproxy.cn,direct

RUN mkdir -p /go/src/kong-plugins&&mkdir -p /go/src/go-pluginserver
RUN git clone https://github.com/Kong/go-pluginserver /go/src/go-pluginserver \
&& cd /go/src/go-pluginserver && make

COPY ./ /go/src/kong-plugins
RUN cd /go/src/kong-plugins&& make build

FROM kong:2.2.0-centos

ENV KONG_DATABASE=off
ENV KONG_GO_PLUGINS_DIR=/tmp/go-plugins
ENV KONG_DECLARATIVE_CONFIG=/tmp/config.yml
ENV KONG_PLUGINS=go-kong
COPY --from=builder /go/src/go-pluginserver/go-pluginserver /usr/local/bin/go-pluginserver
RUN mkdir /tmp/go-plugins
COPY --from=builder /go/src/kong-plugins/go-kong.so /tmp/go-plugins/go-kong.so
COPY config.yml /tmp/config.yml

demo :https://github.com/baxiang/go-note/tree/master/kong-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment