can i set “MemorySwap” and “MemorySwappiness” for docker service? I would like to disable memory swap for docker containers (started by docker service) but i don’t want to disable it for host machine. What means value of -1 at “MemorySwappiness”?
Docker version: 17.06.2-ce
Although this question is old, as it has no answer I have decided to post one.
Indeed, disabling memory swap is now supported by just using the option --memory-swap when creating the container. You simply have to set --memory and --memory-swap to the same value, according to the docs.
This is how to do the same in a docker compose file:
services:
mysvc:
...
deploy:
resources:
limits:
memory: 500m
memswap_limit: 500m
i.e. set the total amount of memory+swap that can be used to 500m, which - given there is only 500m of memory - means there is no need for swap so it will be effectively disabled.
For more information about memory swapping, visit this page of the docs about constraining resource access.
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