Mark Oliver's World

Posted: 25/03/2024

Docker Compose Scaling Gotcha Part 2

Check out my previous gotchas!

Today I ran this command to scaled from 5 existing services, to 10 copies of service1

            docker compose -f config.env up -d --scale service1=10 service1
            
          

What do you think happens?

Well, again, not what I was expecting!

I was expecting service1 to have 10 scaled versions (which it did), but what I was NOT expecting is it restarted the previous running 5 versions!

So what is going on?

When you run a docker compose command it looks at the config you have given it with the new command, and compares it to the previous config setup you gave it.

IF the config is different, its default is to restart the existing services to bring them inline with the new configuration.

When you are scaling, that is not necessarily what you want, so you need to be more explicit about what you want it to do.

Fortunately there is a no-recreate option we can provide to compose that tells it you just want to scale the services, and ignore any changes to config for the existing ones.

This makes the command look like this:

            docker compose -f config.env up -d --scale service1=10 --no-recreate service1
            
          

Source

I wish Docker would tell you that services are going to restart before doing it, as on a shared instance, you have no way to identify if the config has changed since starting a service.

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.