Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add scale parameter in yml #1661

Closed
jmmills opened this issue Jul 6, 2015 · 146 comments
Closed

Feature request: add scale parameter in yml #1661

jmmills opened this issue Jul 6, 2015 · 146 comments

Comments

@jmmills
Copy link

jmmills commented Jul 6, 2015

As a user of compose (formally fig), I would like to be able to specify the number of nodes started for any given definition (a.k.a scale) from inside the manifest (yaml configuration file), so that I can ship my cluster definition with my service orchestration.

E.g. syntax:

worker:
    build: rqworker
    scale: 5
    links:
       - redis
    command: rqworker -u tcp://redis 
@aanm
Copy link

aanm commented Jul 6, 2015

@jmmills Can't you start your containers such as: "docker-compose scale worker=5" and that service would start with 5?

@jmmills
Copy link
Author

jmmills commented Jul 6, 2015

@aanm Yes, but I think that functionality should be mirrored as a default in the service definition. Maybe I have a minimal set of workers that should always be running and I want that to be clearly declared as a default.

@prologic
Copy link

prologic commented Jul 7, 2015

@@aanm Do you expect that a docker-compose up should take the scale parameter into account? The only problem with this that I see is that we're introducing parameters into the declarative configuration that are NOT compatible with the underlying Docker / Docker API concepts but very specific to Docker Compose.

If we were to do this going forward; I'd suggest something like:

worker:
    build: rqworker
    $scale: 5
    links:
       - redis
    command: rqworker -u tcp://redis 

Where $<parameter> denotes a Docker Compose specific thing.

@aanand
Copy link

aanand commented Jul 7, 2015

We've gone back and forth on whether scale belongs in the YAML; there's been a PR to add it before (#630). I'm still of the opinion that most people shouldn't put scale numbers in their config, because it makes it less portable, but I understand the use cases for doing so.

Now that we've got a rudimentary way to augment Compose files with extends (and hopefully better ones soon - #1380, #758), the concerns I raised in #630 (comment) are perhaps less of an issue.

@jamshid
Copy link

jamshid commented Jul 15, 2015

I'd like to set scale=0 in my yml for test-related services that I don't normally want started. I only want to create those services explicitly with docker-compose run or an explicit scale .

@jmmills
Copy link
Author

jmmills commented Jul 19, 2015

@jamshid I've often wanted that, a definition that sets up an environment but doesn't run by default. I've been relegated to creating a base image (which a zero/no-op scale would also help with) in which I run my unit tests out of (via docker run), and then my container composition consumes the base image.

Something like this seems pretty useful for dev configurations

myproject:
    build: .
    command: nosetests
    scale: 0
    links:
       - redis
redis:
    image: redis
apiserver:
    image: myproject
    command: plackup
    links:
       - redis
workerserver:
    image: myproject
    command: rqworker
    links:
        - redis

@prologic
Copy link

@jamshid @jmmills What about a enabled parameter/key in the YAML file per service? Such that you can disable/enable a service?

@jmmills
Copy link
Author

jmmills commented Jul 21, 2015

@prologic Why do that when the a "scale" parameter would solve both needs?
If you want to imagine a running process/container as an instance of a class, one could even name it instances

@prologic
Copy link

@jmmills I'm just trying to find a solution to your use-case that doesn't involve breaking the current docker-compose as such. I do tend to think scale=0 doesn't seem that fitting and I'm in two minds about whether scale=X should even be part of Compose itself.

@jmmills
Copy link
Author

jmmills commented Jul 25, 2015

In my opinion scale (or number of copies) is part of the composition of a service, thus should be included in compose.

@prologic
Copy link

Well I think we either have a scale=0 or disabled key.

@JeanMertz
Copy link

👍 on having the capability of setting a default scale size for an instance. And I agree, once scale is in, there is no need for a disabled key, as you'd simply set scale to 0.

@Filirom1
Copy link

Filirom1 commented Aug 3, 2015

+1

@jmmills
Copy link
Author

jmmills commented Aug 4, 2015

Also, another use case: What if I want to scale the number of containers but don't want to background all of the services, or have to jump over to another terminal (or process) and set my scale numbers...
e.g:

$ docker-compose up && docker scale thing=4

Doesn't work because up doesn't exit.
But if my composition file sets the scale of my containers...

$ docker-compose up

Becomes DWIM.

@prologic
Copy link

prologic commented Aug 4, 2015

I'm not sure that I really like this; all of a sudden up takes on two capabilities:

  • Bring any containers up that don't have scale parameter.
  • Bring any containers up that have scale=0.

We're now abusing the "up" command really. "Scale" also takes on new meaning in that it now does two things:

  • scale containers up/down
  • Disable containers/services by way of ``scale=0`

@jmmills
Copy link
Author

jmmills commented Aug 4, 2015

Why would up bring up containers with a scale=0?
Build would build images with a scale=0, thus facilitating a base image need.

@prologic
Copy link

prologic commented Aug 4, 2015

I could be wrong but reading your last comment it kind of implied that :)

@jmmills
Copy link
Author

jmmills commented Aug 4, 2015

Let me elaborate:

base_thing:
    build: .
    scale: 0

thing:
    image: base_thing
    # scale: 1 implied by default

workers_for_thing:
    image: some_other_image
    scale: 4
    links:
      - thing

test_harness:
    image: base_thing
    command: nosetests --where=my_test_code_dir --all-modules
    scale: 0

Now, expected behavior: docker-compose build builds any containers with "build" (does compose pull in external images on build? don't remember), docker-compose up would run anything with a positive scale (default is 1), docker-compose run test_harness would build "base_thing" if needed and run my one command. Savvy? :)

Edit: docker-compose up would run 1 "thing" and 4 "workers_for_thing"

@prologic
Copy link

prologic commented Aug 4, 2015

Okay :) Thanks; your example makes a bi more sense and a bit clearer as to the intention of scale=0

I think docker-compose "pulls" images on up / run.

@Miuler
Copy link

Miuler commented Aug 8, 2015

I need create recipe indicate number of de intances (scale), for test, production, qa, etc.

@mclate
Copy link

mclate commented Aug 11, 2015

+1 for scale=X. This would be very helpful.
And +1 for @jmmills comment with configuration description and expected results.

@verges-io
Copy link

Yay! for scale=x. Initializing a set of containers would definately help to identify potential race conditions when setting up cluster configurations.

@michaelcontento
Copy link

+1 for scale=x (including scale=0 to disable services for the initial docker-compose up)

@ymmijgno
Copy link

ymmijgno commented Sep 8, 2015

+1 for scale=x.

@aanm
Copy link

aanm commented Sep 8, 2015

x is NaN, I would propose -1 instead.

@samuelololol
Copy link

+1 for scale=x.

@sutyrin
Copy link

sutyrin commented Oct 4, 2015

+1

1 similar comment
@PaulPetring
Copy link

+1

@westlakem
Copy link

westlakem commented Mar 21, 2017 via email

@alwaysastudent
Copy link

@westlakem - that feature is for swarm. It is not for the regular service scaling.

@cgarciae
Copy link

cgarciae commented Apr 7, 2017

So many pros, few cons. What is the matter with this issue?

@matti
Copy link

matti commented Apr 8, 2017

There is a more recent proposal about completely removing the scale command in #2496

I really dont understand why or why there is no initial_scale: 3 option in compose file (I do understand why it can not be just scale: 3)

@shin-
Copy link

shin- commented Jul 18, 2017

Implemented back in 1.13.0. Thank you everyone for your feedback and patience.

@shin- shin- closed this as completed Jul 18, 2017
@greenscar
Copy link

@shin- Why is this considered closed? In managing large scale apps where EVERYTHING is automated & in version control, I now must modify my Ansible which executes Docker to define how many instances of a service will be running.

Ansible should be setting up everything so Docker can run. Docker should be defining how many instances of a service the app needs. Now it's Docker's responsibility to know the inventory of services but Ansible's responsibility to call Docker so it knows how many containers to spin up?

@shin-
Copy link

shin- commented Jul 24, 2017

@greenscar Sorry, I'm not exactly sure what the problem is - are you unhappy about the way the feature has been implemented? If so, in what way can we make it better?

@cgarciae
Copy link

cgarciae commented Aug 2, 2017

Why is this not present in version 3? Extreamly confusing since "deploy.replicas" and "up" are not equivalente, you could say this feature is missing in v3.

@shin-
Copy link

shin- commented Aug 2, 2017

@cgarciae deploy.replicas serves the same purpose as scale. Why are they not equivalent in your view?

@cgarciae
Copy link

cgarciae commented Aug 3, 2017

@shin- If I dont want to create a swarm and only use docker-compose up -d, docker compose tells me it will ignore the "deploy" settings.

@shin-
Copy link

shin- commented Aug 3, 2017

@cgarciae Why are you using a v3 file if you don't want to create a Swarm?

@aphillipo
Copy link

aphillipo commented Aug 3, 2017

I think everyone using docker expects the scale parameter to work for either docker 2 or 3 files. There is no reason for it not to and it could even set the default value for deploy.replicas as well. If deploy.replicas is set it therefore overrides scale in swarm. What is wrong with this picture apart from it being what everyone expects to happen (and of course if you don't like it no need to use it in your docker-compose.yml)?

@boscowitch
Copy link

The missing scale parameter made a servie fail, since i forgot to scale it up like it was before since the last redeloy -.- why is this not a thing it would save service and maybe even lifes depending on what its running

@tsloughter
Copy link

Just hit this issue as well. Seems there is no way to specify how many of a service to start from within the docker compose config? It is even more confusing that the docker compose documentation has a lot of documentation for things that don't work with docker-compose...

@tsloughter
Copy link

Oh wait, so if i change my docker compose config to version: "2.2" then I can use scale: 2 but if one were to want to go to a later version there is no longer an option to do this?

@tsloughter
Copy link

Ok, I see this issue of "version" not really meaning versions has already been brought up, #4693

@freesh
Copy link

freesh commented Jul 1, 2018

I use v3.6 because i need some configs that does not exist in 2.2. For local development i use no swarm, but i want to set scale=0 to some containers in my docker-compose.overrides.yml. Because some of them are just for buildprocesses like the frontendbuild container. This container shares some volumes with other running containers, but should not started together with these other containers on docker-compose up. So the buildcontainer just runs with the run command. Yes i can set the --scale param on calling docker-compose up, but i think it is better to write it directly to the configuration. :)

@samrocketman
Copy link

samrocketman commented Sep 12, 2018

Thanks for the scale parameter. I was able to use it in a non-production docker-compose.yml so that anybody could use a HA configuration of Consul and Vault. The scale parameter made provisioning a local HA configuration easy. https://github.com/samrocketman/docker-compose-ha-consul-vault-ui

In this case, only intended for somebody to try out Consul and Vault in a HA configuration and use Consul DNS.

@jjsaunier
Copy link

jjsaunier commented Sep 12, 2018

Which version of docker compose are you running on ? Since v3 this feature has been dropped (By drop, I mean, never implemented), so it's ignored. See https://docs.docker.com/compose/reference/scale/

@samrocketman
Copy link

samrocketman commented Sep 12, 2018

I don’t ever use v3 format due to missing features. I tend to use the lowest 2.1 or 2.2 format depending on what features I’m using.

Edit: not to say I avoid v3 format. Just that when I go to write a compose file it is usually missing what I want to use.

@jjsaunier
Copy link

jjsaunier commented Sep 12, 2018

Ok, I guessed you speak about docker compose with swarm stack, that's why. I never tried, but it's weird to talk about HA with docker compose without orchestrator and mutli node. Is it for "poc" or testing purpose ? Anyway, I never tried in this context

@samrocketman
Copy link

In this case, the HA simply refers to a consul cluster and a vault cluster. It is meant to serve as a proof of concept available for experimentation and ease of bootstrap. The HA does not refer to docker HA or even multi-machine HA. It's only HA in that the person experimenting can kill one of the cluster containers and see that the consul and/or vault service is not affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests