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!

5
  • I have a similar requirement. Have you found a solution? Commented Aug 18, 2021 at 6:53
  • Hi, have you found a solution? Commented Nov 11, 2021 at 13:04
  • @SachinTanpure unfortunately no Commented May 25, 2022 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. Commented May 25, 2022 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: docs.konghq.com/deck Commented May 25, 2022 at 16:04

1 Answer 1

0

with a simple curl command to write a text file: Once the container is running, i use $ docker exec -it qbittorrent /bin/bash to run this curl command inside the container: curl -o example. txt ' https://example.com. This works as expected: $ ls -al reveals that example.

Sign up to request clarification or add additional context in comments.

1 Comment

I know this, but I am looking for solution through docker compose file only, and not through command prompt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.