Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker service disable memory swap

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

like image 590
user1816532 Avatar asked Oct 27 '25 10:10

user1816532


1 Answers

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.