Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - cpu limit configuration

Tags:

docker

I would like to set limitation of cpu resource, and found this docker-compose setting file below.

version: '3'
services:
  redis:
    image: redis:alpine
    deploy:
      resources:
        limits:
          cpus: '0.001'
          memory: 50M
        reservations:
          cpus: '0.0001'
          memory: 20M

BUT I don't know what 0.001 mean in here. It will use 0.1% of total cpu capacity? and some document said it can be set more than 1. what happen If i set more than 1?

and What is default value of resource.limits.cpus and resource.limits.cpus.memory?

like image 741
J.Done Avatar asked Mar 21 '26 00:03

J.Done


2 Answers

By default a container has limitless access to the host's cpu. Limits allow you to configure resources that are available to a container.

A cpus value of 0.001 will mean for each one second, a 1 millisecond will be available to the container.

A value greater than 1 will make sense when you think of hosts with multi-cpus. A value of 2 for instance will mean the container will be given access for at most 2 cpus.

like image 166
yamenk Avatar answered Mar 23 '26 23:03

yamenk


The limits are the maximum docker will use for the container. The reservations are how much it will set aside for the container i.e. prevent other containers from using.

CPU is measured in percentage of a second on a single CPU. So the example you have will limit you to 0.1% of a CPU (1ms/s), which might be useful for some I/O bound tasks. '1.0' would allow one CPU to be used entirely, and higher values would allow multiple CPUs to be allocated (or reserved) to the container.

This answer has some graphs showing the effects.

like image 28
Alex Taylor Avatar answered Mar 23 '26 23:03

Alex Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!