0

I am fairly new to docker.

My problem is - I have a multi container application(zookeeper, kafka, producer, consumer) in which I want to run the producer and the consumer containers only after the zookeeper and kafka containers are up and running. How to edit the docker-compose file and achieve that? Thanks in advance

2 Answers 2

1

The depends_on instruction only allows you to manage the starting order.
However, it does not wait for your service to be up and running before triggering the next.

If you want to start a service after your dependance is up, then you'll have to look at tools like wait-for-it or dockerize.

You can find more info on the official Docker documentation

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

Comments

0

Check the depends_on directive in the docker-compose documentation.

__ from the docs __

depends_on Express dependency between services, Service dependencies cause the following behaviors:

docker-compose up starts services in dependency order. In the following example, db and redis are started before web.

docker-compose up SERVICE automatically includes SERVICE’s dependencies. In the following example, docker-compose up web also creates and starts db and redis.

docker-compose stop stops services in dependency order. In the following example, web is stopped before db and redis.

Simple example:

version: "3.7"
services:
  web:
    build: .
    depends_on:
      - db
      - redis
  redis:
    image: redis
  db:
    image: postgres

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.