6

I have the following Docker compose file and I am trying to use wait-for-it.sh, so that the control center comes up after Kafka broker is available

  control-center:
    image: confluentinc/cp-enterprise-control-center
    hostname: control-center
    restart: always
    depends_on:
      - zookeeper
      - kafka
      - schema_registry
      - connect
    command: ["./wait-for-it.sh", "kafka:9092"]

I get the below error when I execute docker-compose up:

Cannot start service control-center: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"./wait-for-it.sh\": stat ./wait-for-it.sh: no such file or directory": unknown

I am on Windows 10, using Docker for windows and PowerShell.

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
zooes
  • 1,280
  • 3
  • 15
  • 21
  • it doesn't look like the default image has that script. https://github.com/confluentinc/cp-docker-images/search?utf8=%E2%9C%93&q=wait-for-it&type= Where did you get that script name from? – Alex028502 Feb 28 '18 at 05:03
  • There is a link to the script in this link - https://docs.docker.com/compose/startup-order/ – zooes Feb 28 '18 at 05:14
  • I think you have to build the container with that script on it. It does not come with docker-compose or with that container. – Alex028502 Feb 28 '18 at 05:17
  • Are you using docker compose yaml version 2 or 3? – Alex028502 Feb 28 '18 at 05:17

1 Answers1

10

./wait-for-it.sh will only work if you use an image that has it. You can create your own Dockerfile that extends confluentinc/cp-enterprise-control-center and puts on the wrapper script for the start command.

You can accomplish something similar with docker compose yaml version 2, a healthcheck on the kafka container, and depends_on.

I don't think this works in compose file version 3.

something like this in the control-center section:

depends_on:
  kafka:
    condition: service_healthy

something like this in the kafka section: (no idea if that curl command will check kafka properly. there might be a better command)

healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:9092"]
  interval: 1m30s
  timeout: 10s
  retries: 3
  start_period: 40s

(from https://docs.docker.com/compose/compose-file/compose-file-v2 )

and then maybe this at the top

version: '2.3'

I think they say somewhere that compose file version 3 is really for docker swarm, which is why it doesn't support this feature, and that if you are not using docker swarm you can stick with version 2.

...

The above is all if waiting for the other container to start is what you want to do. What is the alternative to condition form of depends_on in docker-compose Version 3? explains that this might no longer be the recommended way of doing things, because it won't handle container restarts.

I guess this depends if your docker compose set-up is for testing or for production.

Alex028502
  • 3,486
  • 2
  • 23
  • 50