1

I have setup kong docker container. it's starting with docker compose file:

kong:
image: "${KONG_DOCKER_TAG}" 
user: ${KONG_USER}
depends_on:
  - kong-database
  - kong-migrations
environment:
  KONG_ADMIN_ACCESS_LOG: /dev/stdout
  KONG_ADMIN_ERROR_LOG: /dev/stderr
  KONG_ADMIN_LISTEN: '0.0.0.0:8001'
  KONG_CASSANDRA_CONTACT_POINTS: ${KONG_CASSANDRA_CONTACT_POINTS}
  KONG_DATABASE: ${KONG_DATABASE}
  KONG_PG_DATABASE: ${KONG_PG_DATABASE}
  KONG_PG_HOST: ${KONG_PG_HOST}
  KONG_PROXY_LISTEN: '0.0.0.0:8000'
  KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443
  KONG_NGINX_HTTP_INCLUDE: custom-nginx-kong.conf
  KONG_PG_USER: ${KONG_PG_USER}
  KONG_PROXY_ACCESS_LOG: /dev/stdout
  KONG_PROXY_ERROR_LOG: /dev/stderr
  KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}
networks:
  - external-network
configs: 
  - source: kong-config
    target: /usr/local/kong/custom-nginx-kong.conf
    # Permissions -r--r--r--
    mode: 0444
healthcheck:
  test: ["CMD", "curl", "-f", "http://kong:8001"]
  interval: 5s
  timeout: 2s
  retries: 15
restart: on-failure
deploy:
  restart_policy:
    condition: on-failure
  labels:
    com.docker.lb.hosts: ${APP_URL_KONG}
    com.docker.lb.port: 8080
    com.docker.lb.network: external-network
    com.docker.lb.backend_mode: vip

I want to execute curl commands eg. to add new service in kong like below post command immediately after my container is created automatically either through some script or using the below command. but How can I setup this automation through above docker-compose file? please help me to add services automatically on startup though docker compose!!!

curl -i -X POST http://<admin-hostname>:8001/services \
  --data name=example_service \
  --data url='http://mockbin.org'

Thanks in advance!

Priyanka Wagh
  • 615
  • 1
  • 8
  • 17
  • I have a similar requirement. Have you found a solution? – Sachin Tanpure Aug 18 '21 at 06:53
  • Hi, have you found a solution? – USHKA Nov 11 '21 at 13:04
  • @SachinTanpure unfortunately no – Priyanka Wagh May 25 '22 at 14:57
  • @batiuszka_maroz unfortunately no... if anybody knows please text here for other's future reference. I started using curl command from cmd since my organization had some docs which allowed me to access docker container through local cmd. – Priyanka Wagh May 25 '22 at 14:59
  • 1
    @PriyankaWagh Well I found solution that worked for me. So instead of using curl, I used decK, it's a program that "helps manage Kong's configuration in a declarative fashion". You write your whole config in `.yaml` file, very convenient. As far as I remember there were some problems with setting up everything but in the long run I think it's definitely worth it. Link to docs: https://docs.konghq.com/deck/ – USHKA May 25 '22 at 16:04

0 Answers0