Posted: 13/01/2023
Docker Compose Scaling Gotcha
Today I ran this command:
docker-compose up -d --scale service1=10
Then ran this command:
docker-compose up -d --scale anotherservice2=10
What do you think happens?
Well not what I was expecting.
I was expecting
service1
to have 10 scaled versions, and
anotherservice2
to have 10 scaled versions.
What I got was
service1
was scaled back down to the default in the compose file (in this case 5), and
anotherservice2
was bought up to 10.
Why does this happen? Would this have worked?
docker-compose up -d --scale anotherservice2=10 anotherservice2
Turns out YES!
So what is going on?
Lets break the command down...
-
docker-compose up -d
says bring the containers in the compose file up and detach from them. -
--scale anotherservice2=10
says we want to ignore the scale options in the compose file foranotherservice2
and have 10 of them instead. -
anotherservice2
says only apply the previous options to theanotherservice2
I can understand why, now I look at the command, but I would have preferred an indication that it would take
service1
replicas down too.
Oh well another reset of the number of days since I took out PRODUCTION!
Thanks for reading this post.
If you want to reach out, catch me on Twitter!
I am always open to mentoring people, so get in touch.