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