snippetMinor
How to create replicas in docker-compose when `scale` is deprecated?
Viewed 0 times
replicascreatedockerdeprecatedcomposehowscalewhen
Problem
According to docker-compose issue #5586,
As alternate solutions, you can scale services from the command line with docker-compose:
I'm not too fond of this solution since in my understanding
Another option is to run docker-compose in
In that case,
What would you suggest to replace the docker-compose v2
scale is deprecated. The replacement is deploy.replicas but that latter is not handled by docker-compose, only by docker stack implying you have to run Docker in swarm mode.As alternate solutions, you can scale services from the command line with docker-compose:
docker-compose up --scale app=3I'm not too fond of this solution since in my understanding
docker-compose.yml is supposed to be self-contained and should not depend on command line options. Another option is to run docker-compose in
--compatibility mode:docker-compose --compatibility upIn that case,
docker-compose will translate some deploy entries into their version 2 equivalent. But because of the name of that option, and because of the warnings in the docs, it does not look like a mid- to long-term solution.What would you suggest to replace the docker-compose v2
scale option?Solution
@decoomanj on github indicated that
According to mrampant-nist on github one has to use
Let's test this. First of all all docker-compose.yml is needed:
and issuing:
results in:
Applying @decoomanj's suggestion, i.e. replacing replicas:
results in:
Running
In conclusion,
scale has to be replaced by deploy in conjunction with replicas. According to mrampant-nist on github one has to use
--compatibility as well.Let's test this. First of all all docker-compose.yml is needed:
version: '3.3'
services:
nginx:
image: nginx
scale: 6and issuing:
docker-compose upresults in:
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.nginx: 'scale'Applying @decoomanj's suggestion, i.e. replacing replicas:
version: '3.3'
services:
nginx:
image: nginx
deploy:
replicas: 6results in:
WARNING: Some services (nginx) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.Running
docker-compose --compatibility up starts 6 services:CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f19aa54634d7 nginx "nginx -g 'daemon of…" 5 seconds ago Up 4 seconds 80/tcp 6233_nginx_5
749cff4ac1c3 nginx "nginx -g 'daemon of…" 5 seconds ago Up 3 seconds 80/tcp 6233_nginx_3
b86ed7b217fe nginx "nginx -g 'daemon of…" 5 seconds ago Up 1 second 80/tcp 6233_nginx_6
0b92e5ef4a0e nginx "nginx -g 'daemon of…" 5 seconds ago Up 2 seconds 80/tcp 6233_nginx_2
e414bca52b53 nginx "nginx -g 'daemon of…" 5 seconds ago Up 4 seconds 80/tcp 6233_nginx_4
e9f33dc634a8 nginx "nginx -g 'daemon of…" 6 seconds ago Up 5 seconds 80/tcp 6233_nginx_1In conclusion,
replicas has to be replaced by deploy and replicas and --compatibility is needed to solve the issue.Code Snippets
version: '3.3'
services:
nginx:
image: nginx
scale: 6docker-compose upERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.nginx: 'scale'version: '3.3'
services:
nginx:
image: nginx
deploy:
replicas: 6WARNING: Some services (nginx) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.Context
StackExchange DevOps Q#6233, answer score: 3
Revisions (0)
No revisions yet.