'Initiate multiple replicas of each container on one VPS with multiple cores when using Docker Swarm?

I have a VPS running Ubuntu 20.04 with 8 CPU cores. I'm planning to use Docker in Swarm mode to serve the frontend (Vue), backend (Django) and database (PostgreSQL) through a docker-compose.yml file.

When I execute docker swarm init, Docker starts 3 containers (frontend, backend and database).

Will a single replica of each container utilize all 8 CPU cores? Or should I initiate more replicas to utilize all 8 CPU cores of my VPS?



Solution 1:[1]

By default, if you do not change any of the default settings or set any limits inside the compose files (resource constraints more on this - https://docs.docker.com/config/containers/resource_constraints/ or compose https://docs.docker.com/compose/compose-file/compose-file-v3/#resources), container has unlimited CPU limit and unlimited MEM limit. So one replica of each service will have ALL of the memory available if the application has means to use it.

You would probably still want to look into more replicas for options on rolling updates (updates of the SW with limited or close to zero downtime).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matic1123