@@ -2080,7 +2080,23 @@ def _parse_compose_file(self):
2080
2080
container_names_by_service = {}
2081
2081
self .services = services
2082
2082
for service_name , service_desc in services .items ():
2083
- replicas = try_int (service_desc .get ("deploy" , {}).get ("replicas" ), fallback = 1 )
2083
+ replicas = 1
2084
+ if "scale" in args and args .scale is not None :
2085
+ # Check `--scale` args from CLI command
2086
+ scale_args = args .scale .split ('=' )
2087
+ if service_name == scale_args [0 ]:
2088
+ replicas = try_int (scale_args [1 ], fallback = 1 )
2089
+ elif "scale" in service_desc :
2090
+ # Check `scale` value from compose yaml file
2091
+ replicas = try_int (service_desc .get ("scale" ), fallback = 1 )
2092
+ elif (
2093
+ "deploy" in service_desc
2094
+ and "replicas" in service_desc .get ("deploy" , {})
2095
+ and "replicated" == service_desc .get ("deploy" , {}).get ("mode" , '' )
2096
+ ):
2097
+ # Check `deploy: replicas:` value from compose yaml file
2098
+ # Note: All conditions are necessary to handle case
2099
+ replicas = try_int (service_desc .get ("deploy" , {}).get ("replicas" ), fallback = 1 )
2084
2100
2085
2101
container_names_by_service [service_name ] = []
2086
2102
for num in range (1 , replicas + 1 ):
@@ -3366,12 +3382,13 @@ def compose_up_parse(parser):
3366
3382
action = "store_true" ,
3367
3383
help = "Remove containers for services not defined in the Compose file." ,
3368
3384
)
3385
+ # `--scale` argument needs to store as single value and not append,
3386
+ # as multiple scale values could be confusing.
3369
3387
parser .add_argument (
3370
3388
"--scale" ,
3371
3389
metavar = "SERVICE=NUM" ,
3372
- action = "append" ,
3373
- help = "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if "
3374
- "present." ,
3390
+ help = "Scale SERVICE to NUM instances. "
3391
+ "Overrides the `scale` setting in the Compose file if present." ,
3375
3392
)
3376
3393
parser .add_argument (
3377
3394
"--exit-code-from" ,
0 commit comments