@@ -2080,7 +2080,17 @@ 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 = try_int (args .scale , fallback = 1 ) if "scale" in args else 1
2084
+ # Skip `scale` or `replicas` check from compose yaml
2085
+ # if `--scale=<NUM>` is specifiec in CLI arg
2086
+ if 1 == replicas :
2087
+ if "scale" in service_desc :
2088
+ # Attempt to read parameter scale for service from compose yaml file
2089
+ replicas = try_int (service_desc .get ("scale" ), fallback = 1 )
2090
+ if "replicas" in service_desc :
2091
+ # Attempt to read parameter deploy.replicas for service from compose yaml file
2092
+ # Note: both conditions are necessary to handle case if `has_key("deploy")` is false
2093
+ replicas = try_int (service_desc .get ("deploy" , {}).get ("replicas" ), fallback = 1 )
2084
2094
2085
2095
container_names_by_service [service_name ] = []
2086
2096
for num in range (1 , replicas + 1 ):
@@ -3366,12 +3376,15 @@ def compose_up_parse(parser):
3366
3376
action = "store_true" ,
3367
3377
help = "Remove containers for services not defined in the Compose file." ,
3368
3378
)
3379
+ # `--scale` argument needs to store as single valye and not append,
3380
+ # as multiple scale values could be confusing.
3369
3381
parser .add_argument (
3370
3382
"--scale" ,
3371
- metavar = "SERVICE=NUM" ,
3372
- action = "append" ,
3383
+ # action="store",
3373
3384
help = "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if "
3374
3385
"present." ,
3386
+ metavar = "SERVICE=NUM" ,
3387
+ type = int ,
3375
3388
)
3376
3389
parser .add_argument (
3377
3390
"--exit-code-from" ,
0 commit comments