docker kong error to get connection with postgres

  docker, kong, postgresql

My dockerCompose.yml:

version: "3.7"

networks: 
  kong-net:

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

  #######################################
  # Kong database migration
  #######################################
  kong-migration:
    image: kong:2.0.3-alpine
    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
    depends_on:
      - kong-database

  #######################################
  # Kong: The API Gateway
  #######################################
  kong:
    image: kong:2.0.3-alpine
    restart: on-failure
    container_name: kong
    networks:
      - kong-net
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-database
      KONG_PG_DATABASE: kong
      KONG_PG_USER: kong
      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:[email protected]:5434/konga"
    networks:
      - kong-net
    restart: on-failure
    links:
      - kong-database
    depends_on:
      - kong-database
  
  #######################################
  # Konga: Kong GUI
  #######################################
  konga:
    image: pantsel/konga:latest
    container_name: konga
    restart: always
    networks:
      - kong-net
    environment:
      DB_ADAPTER: postgres
      DB_HOST: kong-database
      DB_USER: kong
      TOKEN_SECRET: FUEDASHFUAEHFEUAHFEU;
      DB_DATABASE: kong
      NODE_ENV: production
    depends_on:
      - kong-database
    ports:
      - "1337:1337"

but i get this on docker – compose logs on my container KONG:

kong                  | 2020/09/02 21:51:04 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:20: New migrations available; run 'kong migrations up' to proceed
kong                  | stack traceback:
kong                  |         [C]: in function 'error'
kong                  |         /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:20: in function 'check_state'
kong                  |         /usr/local/share/lua/5.1/kong/init.lua:392: in function 'init'
kong                  |         init_by_lua:3: in main chunk
kong                  | nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:20: New migrations available; run 'kong migrations up' to proceed
kong                  | stack traceback:
kong                  |         [C]: in function 'error'
kong                  |         /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:20: in function 'check_state'
kong                  |         /usr/local/share/lua/5.1/kong/init.lua:392: in function 'init'
kong                  |         init_by_lua:3: in main chunk
kong                  | 2020/09/02 21:51:08 [notice] 1#0: using the "epoll" event method
kong                  | 2020/09/02 21:51:08 [notice] 1#0: openresty/1.15.8.3
kong                  | 2020/09/02 21:51:08 [notice] 1#0: built by gcc 9.2.0 (Alpine 9.2.0) 
kong                  | 2020/09/02 21:51:08 [notice] 1#0: OS: Linux 5.4.0-45-generic
kong                  | 2020/09/02 21:51:08 [notice] 1#0: getrlimit(RLIMIT_NOFILE): 1048576:1048576
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker processes
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 22
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 23
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 24
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 25
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 26
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 27
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 28
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 29
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 30
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 31
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 32
kong                  | 2020/09/02 21:51:08 [notice] 1#0: start worker process 33
kong                  | 2020/09/02 21:51:08 [notice] 22#0: *5 [lua] cache_warmup.lua:46: cache_warmup_single_entity(): Preloading 'services' into the core_cache..., context: init_worker_by_lua*
kong                  | 2020/09/02 21:51:08 [notice] 22#0: *5 [lua] cache_warmup.lua:85: cache_warmup_single_entity(): finished preloading 'services' into the core_cache (in 0ms), context: init_worker_by_lua*
kong                  | 2020/09/02 21:51:08 [notice] 22#0: *5 [lua] cache_warmup.lua:46: cache_warmup_single_entity(): Preloading 'plugins' into the core_cache..., context: init_worker_by_lua*
kong                  | 2020/09/02 21:51:08 [notice] 22#0: *5 [lua] cache_warmup.lua:85: cache_warmup_single_entity(): finished preloading 'plugins' into the core_cache (in 0ms), context: init_worker_by_lua*

on my container Konga-prepare:

konga-prepare_1       | debug: Preparing database...
konga-prepare_1       | Using postgres DB Adapter.
konga-prepare_1       | Failed to connect to DB Error: connect ECONNREFUSED 192.168.64.2:5434
konga-prepare_1       |     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
konga-prepare_1       |   errno: 'ECONNREFUSED',
konga-prepare_1       |   code: 'ECONNREFUSED',
konga-prepare_1       |   syscall: 'connect',
konga-prepare_1       |   address: '192.168.64.2',
konga-prepare_1       |   port: 5434
konga-prepare_1       | }

on my container konga:

konga                 |   _e: error: relation "public.konga_users" does not exist
konga                 |       at Connection.parseE (/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:539:11)
konga                 |       at Connection.parseMessage (/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:366:17)
konga                 |       at Socket.<anonymous> (/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:105:22)
konga                 |       at Socket.emit (events.js:310:20)
konga                 |       at Socket.EventEmitter.emit (domain.js:482:12)
konga                 |       at addChunk (_stream_readable.js:286:12)
konga                 |       at readableAddChunk (_stream_readable.js:268:9)
konga                 |       at Socket.Readable.push (_stream_readable.js:209:10)
konga                 |       at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
konga                 |     length: 118,
konga                 |     severity: 'ERROR',
konga                 |     code: '42P01',
konga                 |     detail: undefined,
konga                 |     hint: undefined,
konga                 |     position: '377',
konga                 |     internalPosition: undefined,
konga                 |     internalQuery: undefined,
konga                 |     where: undefined,
konga                 |     schema: undefined,
konga                 |     table: undefined,
konga                 |     column: undefined,
konga                 |     dataType: undefined,
konga                 |     constraint: undefined,
konga                 |     file: 'parse_relation.c',
konga                 |     line: '1159',
konga                 |     routine: 'parserOpenTable'
konga                 |   },
konga                 |   rawStack: 'error: relation "public.konga_users" does not existn' +
konga                 |     '    at Connection.parseE (/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:539:11)n' +
konga                 |     '    at Connection.parseMessage (/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:366:17)n' +
konga                 |     '    at Socket.<anonymous> (/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:105:22)n' +
konga                 |     '    at Socket.emit (events.js:310:20)n' +
konga                 |     '    at Socket.EventEmitter.emit (domain.js:482:12)n' +
konga                 |     '    at addChunk (_stream_readable.js:286:12)n' +
konga                 |     '    at readableAddChunk (_stream_readable.js:268:9)n' +
konga                 |     '    at Socket.Readable.push (_stream_readable.js:209:10)n' +
konga                 |     '    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)',
konga                 |   details: 'Details:  error: relation "public.konga_users" does not existn'
konga                 | }

I’m not able to imagine the reason for the error, my dockercompose seems to be configured correctly.
I configured the right port, but I have these errors I tried to fix and I can’t.

Source: Docker Questions

LEAVE A COMMENT