0

I have a docker-compose.yaml file that looks like this:

version: '3'
services:
  keycloak:
    image: quay.io/keycloak/keycloak:19.0.0
    command: "start-dev"
    ports:
      - 8443:8443
    healthcheck:
      test: "curl -f http://0.0.0.0:8443"
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 10s
    environment:
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: password123
      KC_HTTP_PORT: 8443

  keycloak-setup:
    image: quay.io/keycloak/keycloak:19.0.0
    entrypoint: "/bin/bash"
    command: -c "kcadm.sh config credentials --server http://keycloak:8443 --realm master --user admin --password password123 && kcadm.sh create realms -s realm=myrealm -s enabled=true -o"
    depends_on:
      keycloak:
        condition: service_healthy
    environment:
      PATH: /opt/keycloak/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

It works OK, but the keycloak-setup command is getting very long.

I would like to break it up a bit like this:

  keycloak-setup:
    image: quay.io/keycloak/keycloak:19.0.0
    entrypoint: [ /bin/bash, -c ]
    command: |
      kcadm.sh config credentials --server http://keycloak:8443 --realm master --user admin --password password123 
      && kcadm.sh create realms -s realm=myrealm -s enabled=true -o
    depends_on:
      keycloak:
        condition: service_healthy
    environment:
      PATH: /opt/keycloak/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

However, this does not work.

How can I set my entrypoint to /bin/bash and execute a multi-line script in Docker Compose?

sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
  • Does this answer your question? [Docker Compose - How to execute multiple commands?](https://stackoverflow.com/questions/30063907/docker-compose-how-to-execute-multiple-commands) – Gastón Schabas May 03 '23 at 20:00

0 Answers0