User Tools

Site Tools


docker:memory_limit

How to specify Memory & CPU limit in docker compose version 3

Источник

deploy:
  resources:
    limits:
      cpus: '0.001'
      memory: 50M
    reservations:
      cpus: '0.0001'
      memory: 20M

More: compose-file-v3/#resources

Swap

memswap_limit

memswap_limit defines the amount of memory the container is allowed to swap to disk. This is a modifier attribute that only has meaning if memory is also set. Using swap lets the container write excess memory requirements to disk when the container has exhausted all the memory that is available to it. There is a performance penalty for applications that swap memory to disk often.

  • If memswap_limit is set to a positive integer, then both memory and memswap_limit must be set. memswap_limit represents the total amount of memory and swap that can be used, and memory controls the amount used by non-swap memory. So if memory=“300m” and memswap_limit=“1g”, the container can use 300m of memory and 700m (1g - 300m) swap.
  • If memswap_limit is set to 0, the setting is ignored, and the value is treated as unset.
  • If memswap_limit is set to the same value as memory, and memory is set to a positive integer, the container does not have access to swap.
  • If memswap_limit is unset, and memory is set, the container can use as much swap as the memory setting, if the host container has swap memory configured. For instance, if memory=“300m” and memswap_limit is not set, the container can use 600m in total of memory and swap.
  • If memswap_limit is explicitly set to -1, the container is allowed to use unlimited swap, up to the amount available on the host system.
docker/memory_limit.txt · Last modified: 2024/05/07 17:14 by Denis Evsyukov