Skip to content

Memory limits in compose specification v3 vs. docker-compose #14185

Description

@Fgerthoffert

Problem description

I find the deploy.resources documentation confusing, which seems to also generate quite a bit of inaccuracy on other sites.

I'm specifically referring to this block:
Screen Shot 2022-01-28 at 10 42 37 AM

It seems to imply that if you're not using docker swarm (in our situation using docker-compose for our CI/tests environments), you cannot set resource limits using v3 of the compose reference.

See below the LIMIT values, which seems to contradict the content of the block.

Docker-compose v2, no memory limits

version: '2.4'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
    environment:
      - discovery.type=single-node
    ports:
      - "9200:9200"
#> docker-compose up -d
#> docker stats
CONTAINER ID   NAME                     CPU %     MEM USAGE / LIMIT    MEM %     NET I/O       BLOCK I/O         PIDS
065b95320d3b   memory_elasticsearch_1   1.18%     1.291GiB / 9.73GiB   13.27%    1.38kB / 0B   5.01MB / 1.53MB   54

Docker-compose v2, with memory limits

version: '2.4'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
    mem_limit: 1gb
    environment:
      - discovery.type=single-node
    ports:
      - "9200:9200"
#> docker-compose up -d
#> docker stats
CONTAINER ID   NAME                     CPU %     MEM USAGE / LIMIT   MEM %     NET I/O       BLOCK I/O        PIDS
9619260c1211   memory_elasticsearch_1   0.96%     1019MiB / 1GiB      99.48%    1.37kB / 0B   74.2MB / 360MB   59

Docker-compose v3, without memory limits

version: '3.9'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
    environment:
      - discovery.type=single-node
    ports:
      - "9200:9200"
#> docker-compose up -d
#> docker stats
CONTAINER ID   NAME                     CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O     PIDS
ac085effc60d   memory_elasticsearch_1   321.34%   1.31GiB / 9.73GiB   13.46%    876B / 0B   0B / 1.28MB   54

Docker-compose v3, with memory limits

version: '3.9'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
    deploy:
      resources:
        limits:
          memory: 1.5G
    environment:
      - discovery.type=single-node
    ports:
      - "9200:9200"
#> docker-compose up -d
#> docker stats
CONTAINER ID   NAME                     CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O    PIDS
5307a8b71914   memory_elasticsearch_1   193.63%   1.216GiB / 1.5GiB   81.05%    876B / 0B   0B / 377kB   33

Problem location

Project version(s) affected

Using Docker Desktop 4.4.2 (73305)

% docker -v
Docker version 20.10.12, build e91ed57
% docker-compose -v
docker-compose version 1.29.2, build 5becea4c

Suggestions for a fix

It would be great if the documentation could be a bit clearer in regards to what is or is not supported when using docker-compose (i.e. "on non swarm deployments").

Thanks a lot,

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions