Docker Swarm memswap_limit not working

Hello all,

for an swarm with elasticsearch, I need to disable swapping in the docker container.

When I read this Documentation, I need to configure the memswap_limit with the same number as the deploy.limits.memory.

But this did not work in a compose file, which is used for a swarm.

Example docker-compose.yml:

version: "3.8"
services:
  elasticsearch:
    memswap_limit: 2G
    image: docker.elastic.co/elasticsearch/elasticsearch:8.11.1-amd64
    logging:
      driver: json-file
      options:
        max-file: '10'
        max-size: 20m
    environment:
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
    volumes:
      - /path/to/folder:/path/to/folder
    ports:
      - 9200:9200
      - 9300:9300
    deploy:
      mode: global
      resources:
        limits:
          memory: 2G
    networks:
      - net

When I issue the command docker stack deploy -f docker-compose.yml stackname I get an error, that the memswap_limit is not supported.

How would I now disable swapping in a swarm container configuration?

Thanks!
M

You read the compose specification for Docker Compose v2, but it seems Docker Swarm doesn’t support this option.

This is an old issue, but still open and docker service create doesn’t have swap limit option either, only memory limit.

Thanks for your answer!

This is pretty bad, since I would need this feature.

I thought it’s bad how slooowly Docker Swarm is moving forward, but even Docker itself has some very basic things that seemingly don’t get fixed for years, even swap for regular service (link).

There’s an “epic” with a whole list of missing pieces (link), we should get some summer interns to finally fix those :laughing:

You could try to create an issue for compose spec (link), it might finally get a simple implementation if it’s accepted there. But it’s just an idea, I have no proof :smile: