jotrocken
jotrocken

Reputation: 2333

How to make docker-compose scale start dependencies?

There is a setup with 1...N application containers which are connected to different backend services. The docker-compose.yml looks like this:

services:
  backend1:
    ...
  backend2:
    ...
  application:
    ...
    depends_on:
      backend1:
        condition: service_healthy
      backend2:
        condition: service_healthy

When starting multiple instances of the application with docker-compose scale SERVICE=INSTANCES the result is this

$ docker-compose scale application=2
Creating and starting application_1 ... done
Creating and starting application_2 ... done
$ docker ps -a 
CONTAINER ID    IMAGE               COMMAND   CREATED          STATUS                     PORTS   NAMES
f4e274552239    application_image   ...       4 minutes ago    Up 4 minutes (unhealthy)           application_1
39f28173087c    application_image   ...       4 minutes ago    Up 4 minutes (unhealthy)           application_2

Obviously, the dependencies are not started. When the a single instance of the service is started instead with docker-compose up application, the dependencies are started correctly:

$ docker-compose up -d application
Creating backend1_1
Creating backend2_1
Creating application_1

After that, a second instance can be added docker scale:

$ docker-compose scale application=2
Creating and starting application_2 ... done

This works fine. But is there some way to let docker-compose scale also start the dependencies? If not, what might be the rationale behind that behavior?

Upvotes: 2

Views: 591

Answers (1)

mickadoo
mickadoo

Reputation: 3483

I don't believe there is a way to do this right now. There is a long, running issue commentary on this topic.

One of the comments mentions that it will be available in version 3 of the schema.

I've tried a minimal version locally:

version: '2'

services:
  a:
    image: alpine
    links:
      - b
    command: sleep 10

  b:
    image: alpine
    command: sleep 10

And the up doesn't work with scale. However (and you probably know this already), you can name all the services in your command, so

docker-compose scale a=2 b=2

creates two of both and did the correct linking.

Upvotes: 2

Related Questions