I want to have a policy in my docker-compose which a docker container memory usage will be higher than the amount of a certain memory limitation it restarts.
This is what I have done so far:
version: '3'
services:
modbus_collector:
build: .
image: modbus_collector:2.0.0
container_name: modbus_collector
restart: unless-stopped
deploy:
resources:
limits:
memory: 28M
I was expecting that to be restarted when the container memory usage exceeds 28M, but when I monitor docker containers by docker stats I see that this container memory usage grow up and not happens about restart!
I also tried by restart: always but the result was the same.
[UPDATE]:
With version 2 it works fine with mem_limit:. But it fails while using version 3, putting them under deploy section doesn't seem worthy unless I am using swarm mode.
Even on version 2.1, I have a problem in restarting the container: limitation applied correctly, but when the container memory usage grows up, this limitation prevents of that but I expected instead of decrease memory it will restart that container.
version: '2.1'
services:
modbus_collector:
build: .
image: modbus_collector:2.0.0
container_name: modbus_collector
restart: unless-stopped
mem_limit: 28m