Run kong with custom nginx configuration on docker

I’m having trouble trying to run kong with custom nginx configuration on docker.
I have simpliest possible template:

worker_processes ${{NGINX_WORKER_PROCESSES}}; # can be set by kong.conf
daemon ${{NGINX_DAEMON}};                     # can be set by kong.conf

pid pids/nginx.pid;                      # this setting is mandatory
error_log logs/error.log ${{LOG_LEVEL}}; # can be set by kong.conf

events {
    use epoll; # custom setting
    multi_accept on;
}

http {
    # include default Kong Nginx config
    include 'nginx-kong.conf';
}

Along with simple Dockerfile:

FROM kong:0.14.1-alpine

COPY . /etc/kong/

CMD kong start --nginx-conf /etc/kong/nginx.template

I then configure, build and run container along with postgresql container with docker-compose, but I believe this part of setup is irrelevant. I tested it before with clean kong:0.14.1-alpine image and it worked.

My setup with custom config returns an error on start:

kong_1               | Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:28: failed to compile nginx config template: [string "TMP"]:77: attempt to index global 'el' (a nil value)
kong_1               | stack traceback:
kong_1               |  [string "TMP"]:77: in function <[string "TMP"]:1>
kong_1               |  [C]: in function 'xpcall'
kong_1               |  /usr/local/share/lua/5.1/pl/template.lua:138: in function 'substitute'
kong_1               |  /usr/local/share/lua/5.1/kong/cmd/utils/prefix_handler.lua:115: in function 'compile_nginx_conf'
kong_1               |  /usr/local/share/lua/5.1/kong/cmd/utils/prefix_handler.lua:246: in function 'prepare_prefix'
kong_1               |  /usr/local/share/lua/5.1/kong/cmd/start.lua:28: in function </usr/local/share/lua/5.1/kong/cmd/start.lua:27>
kong_1               |  [C]: in function 'xpcall'
kong_1               |  /usr/local/share/lua/5.1/kong/cmd/start.lua:27: in function 'cmd_exec'
kong_1               |  /usr/local/share/lua/5.1/kong/cmd/init.lua:87: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:87>
kong_1               |  [C]: in function 'xpcall'
kong_1               |  /usr/local/share/lua/5.1/kong/cmd/init.lua:87: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:44>
kong_1               |  /usr/local/bin/kong:7: in function 'file_gen'
kong_1               |  init_worker_by_lua:48: in function <init_worker_by_lua:46>
kong_1               |  [C]: in function 'xpcall'
kong_1               |  init_worker_by_lua:55: in function <init_worker_by_lua:53>
kong_1               |
kong_1               |   Run with --v (verbose) or --vv (debug) for more details

Did I miss something?

FWIW, the Dockerfile and nginx template you posted worked for me with Docker compose.

Perhaps it is compose related problem then. My docker-compose file looks like this:

version: '3'

volumes:
  kong_db_test:
    driver: local

services:
  kong-postgres:
    image: postgres:9.5-alpine
    volumes:
      - kong_db_test:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: kong
      POSTGRES_USER: kong
      POSTGRES_PASSWORD: e?~&yT0?ts397$wb.4;+
    healthcheck:
      test: ['CMD', 'pg_isready', '-U', 'kong']
      interval: 5s
      timeout: 5s
      retries: 5
  kong-migration:
    image: kong:0.14.1-alpine
    command: 'kong migrations up'
    restart: on-failure
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-postgres
      KONG_PG_PORT: 5432
      KONG_PG_DATABASE: kong
      KONG_PG_USER: kong
      KONG_PG_PASSWORD: e?~&yT0?ts397$wb.4;+
      KONG_LOG_LEVEL: info
    depends_on:
      - kong-postgres
  kong:
    build: ./kong
    #image: kong:0.14.1-alpine
    restart: always
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-postgres
      KONG_PG_PORT: 5432
      KONG_PG_DATABASE: kong
      KONG_PG_USER: kong
      KONG_PG_PASSWORD: e?~&yT0?ts397$wb.4;+
      KONG_LOG_LEVEL: info
    ports:
      - 8000:8000
    depends_on:
      - kong-postgres
      - kong-migration