Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose file memory, cpu limits

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?

like image 458
Adnan Bilaç Avatar asked Apr 25 '17 03:04

Adnan Bilaç


People also ask

Can I limit file size CPU utilization for docker in my machine?

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.

How much CPU can a docker container use?

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.

Does docker have a memory limit?

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.

What is default docker memory limit?

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 .


2 Answers

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 of resources

like image 120
VonC Avatar answered Sep 21 '22 13:09

VonC


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.

like image 27
Gaspar Chilingarov Avatar answered Sep 18 '22 13:09

Gaspar Chilingarov