emoleumassi
emoleumassi

Reputation: 5149

docker-compose run multiple commands for a krakend

how can run multiple commands for. I try to run krakend and export the openapi document.

version: "3"
services:
  krakend_ce:
    image: devopsfaith/krakend:watch
    volumes:
      - ./krakend:/etc/krakend
    ports:
      - "9000:9000"
    command: ["run", "-d", "-c", "/etc/krakend/krakend.json"]
    # how to run krakend openapi export -h

i want to krakend openapi export -hafter container is started

Upvotes: 0

Views: 237

Answers (2)

taik0
taik0

Reputation: 1

You should not use the watch tag to run multiple commands, since it monitors the config files for changes, and restart the service.

If you use any other version (than watch), you can run an sh -c 'your commands; command2' command without problems.

Upvotes: 0

Kevin Kopf
Kevin Kopf

Reputation: 14230

Judging by their Dockerfile from here, they set ENTRYPOINT ["/entrypoint.sh"] and CMD ["krakend" "run" "-c" "/etc/krakend/krakend.json"].

What you need to do, is:

  1. Set entrypoint to /bin/bash.
  2. Create a new bash file to run multiple commands. Something like:
#!/bin/bash
/entrypoint.sh krakend run -c /etc/krakend/krakend.json
# I'm not sure if it runs in foreground or background. For background you can use nohup:
#nohup /entrypoint.sh krakend run -c /etc/krakend/krakend.json &
/entrypoint.sh krakend openapi export -h
  1. Map the file into the container.
  2. Set cmd to use the new file.

I'd build a custom Docker image for that, but setting it in docker-compose.yml is also feasible.

version: "3"
services:
  krakend_ce:
    image: devopsfaith/krakend:watch
    volumes:
      - ./krakend:/etc/krakend
      - ./your-custom-file.sh:/path/to/your/file.sh
    ports:
      - "9000:9000"
    entrypoint: /bin/bash
    command: /path/to/your/file.sh

Upvotes: 1

Related Questions