Feature request: add scale parameter in yml
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
@jmmills Can't you start your containers such as: "docker-compose scale worker=5" and that service would start with 5?
@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.
@@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.
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 https://github.com/docker/compose/pull/630#issuecomment-69210279 are perhaps less of an issue.
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 .
@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
@jamshid @jmmills What about a enabled parameter/key in the YAML file per service? Such that you can disable/enable a service?
@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
@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.
In my opinion scale (or number of copies) is part of the composition of a service, thus should be included in compose.
Well I think we either have a scale=0 or disabled key.
:+1: 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.
+1
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.
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
scaleparameter. - 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`
Why would up bring up containers with a scale=0?
Build would build images with a scale=0, thus facilitating a base image need.
I could be wrong but reading your last comment it kind of implied that :)
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"
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.
I need create recipe indicate number of de intances (scale), for test, production, qa, etc.