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