I am trying use memory and CPU in docker-compose file.
I get below error code:
The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.web: 'resources'
My docker-compose.yml
file is below
version: '3'
services:
web:
build: .
volumes:
- "./app:/home"
ports:
- "8080:8080"
resources:
limits:
cpus: '0.001'
memory: 512M
How can I use CPU, memory with in docker-compose?
Limit Docker Container CPU Usage You can also use the --cpu-shares option to give the container a greater or lesser proportion of CPU cycles. By default, this is set to 1024. To find more options for limiting container CPU usage, please refer to Docker's official documentation.
On windows, a container defaults to using two CPUs. If hyperthreading is available this is one core and two logical processors. If hyperthreading is not available this is two cores and two logical processors.
Docker can enforce hard memory limits, which allow the container to use no more than a given amount of user or system memory, or soft limits, which allow the container to use as much memory as it needs unless certain conditions are met, such as when the kernel detects low memory or contention on the host machine.
Docker Container Memory Limits - Set global memory limit By default, the container can swap the same amount of assigned memory, which means that the overall hard limit would be around 256m when you set --memory 128m .
Docker compose resources were introduced in file format version 3, which needs docker-compose 1.13 or newer. Chances are you are using an older version:. Check the output of:
docker-compose version
See the upgrade guide.
The OP uses docker-compose 1.12, which does not yet support version 3.
solved: I use version: '2' instead of version: '3' in docker-composer file and ı use
mem_limit
instead ofresources
If you are using Docker Compose v.3 configs and running docker-compose up
mode, then this can be useful.
This is not documented anywhere in docker-compose, but you can pass any valid system call setrlimit
option in ulimits
.
So, you can specify in docker-compose.yaml
ulimits:
as:
hard: 130000000
soft: 100000000
memory size is in bytes. After going over this limit your process will get memory allocation exceptions, which you may or may not trap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With