4

I have to use a memory limitation for a service and I also need to use version 3 in the docker-compose file.

My piece of code from the docker-compose.yml is:

version '3'
.
.
.
service1:
  .
  .
  .
  mem_limit: 500m
.
.
.

This with version 2 works and it limits me correctly that service. My question is how to put this limitation with version 3 since I need it.

I hope help, thank you very much

Esther_5
  • 151
  • 2
  • 10
  • Possible duplicate of [Limit resources in docker-compose v3](https://stackoverflow.com/questions/42453473/limit-resources-in-docker-compose-v3) – lependu Nov 19 '18 at 12:20
  • Possible duplicate of - https://stackoverflow.com/questions/42345235/how-to-specify-memory-cpu-limit-in-docker-compose-version-3 – vivekyad4v Nov 19 '18 at 12:56

2 Answers2

1

My working solution:

Here is my docker-compose.yml with a RAM limit of 1GB:

version: "3"

services:
  node:
    container_name: "someName"
    image: "node:16.15.1-buster"
    working_dir: '/var/www/html/theme'
    volumes:
      - ./:/var/www/html/
    ports:
      - "9002:3000"
      - "24002:24002"
    stdin_open: true
    mem_limit: 1GB # <= Memory limitation

After the container creation with docker-compose up -d, check the container statistics:

docker stats someName

CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT   MEM %     NET I/O       BLOCK I/O   PIDS
b6514fe2c63f   someName   0.00%     6.617MiB / 1GiB     0.65%     3.64kB / 0B   0B / 0B     7

The maximum memory limit is actually "1GB".

Eflyax
  • 5,307
  • 2
  • 19
  • 29
-6

from docker https://docs.docker.com/v17.09/compose/compose-file/#replicas doc

version: '3'
services:
  redis:
    image: redis:alpine
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
        reservations:
          cpus: '0.25'
          memory: 20M 
    
Kilian
  • 1,753
  • 13
  • 21