title: Set CPU limit in Docker Compose
body: <p>I got a on-prem server which I would like to deploy many micro-services. I'm using a docker-compose file to declare all services and would like to set the cpu limit. I refer the docs below: <a href="https://docs.docker.com/compose/compose-file/" rel="noreferrer">https://docs.docker.com/compose/compose-file/</a>
  My docker compose file is like: </p>
  
  <pre><code>version: "3.7"
  services:
    redis:
      image: redis:alpine
      deploy:
        resources:
          limits:
            cpus: '2'
            memory: 256M
          reservations:
            cpus: '0.25'
            memory: 64M
    service1:
      image: service1 image
      deploy:
        resources:
          limits:
            cpus: '2'
            memory: 512M
          reservations:
            cpus: '0.25'
            memory: 64M
  
  ...
  </code></pre>
  
  <p>I'm confused to calculate the cpus limits. For example, the cpu is 8 cores. There are 20 microservices. 
  Is there any way I can calculate the cpu limit of each service? Or any formulas to do so?</p>
  
  <p>----- UPDATE ------
  To make it clearer, my main point here is CPU limit. It is because I'd like to send alert if the CPU of one microservice is using 80% of CPU for that microservice. If I don't set the cpu limit, is it true that the microservice CPU usage will be the same with host CPU usage? I don't use Docker's Swarn but Docker only.</p>
  
  <p>Any ideas are really appreciated.</p>
  
  <p>Thanks,</p>