Scale multiple containers of a service in a single host

I am scaling multiple containers of a service on a single linux host by command “docker-compose up –scale”. However, each container can use all the resources (CPU and RAM) of the host. It seems to be useless to scale like that.

Thus, I try to limit availabe CPU and RAM for each container (I am currently using docker-compose version 2) by “cpus” and “mem_limit” tag in docker-compose.yml file.

This is my docker-compose.yml file

version: "2.2"
services:
  test:
    image: test
    mem_limit: 500000000
    container_name: test
    build: ./test
    restart: always
    mem_limit: 500000000
    mem_reservation: 300m
    cpus: 0.5
    networks:
      - test-network
    ports:
      - "9000:80"

But I don’t know that if it is useful to scale multiple containers of a service on a single host? Also, is there any ways to automatically scale this service (scale on demand)?
Thank you,

Source: StackOverflow