Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mem_limit in docker-compose.yml version 3

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

like image 753
Esther_5 Avatar asked Apr 11 '26 20:04

Esther_5


1 Answers

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".

like image 120
35 revs, 24 users 34% Avatar answered Apr 13 '26 10:04

35 revs, 24 users 34%