12

I'm currently having some issues with the shared memory in one of my containers.

I have a docker-compose file in where I expect to be able to set the size. I basically converted an old docker run that had a --shm-size 16gb. I would guess it's as easy as adding shm_size:16gb to my service in the compose file.

Adding it just gives me the info: Ignoring unsupported options: shm_size.

I did check the docs, but it didn't really help me.

Just to clarify, it's not in the build but really for the "running" state.

Does one of you ever had this issue/know how to solve it?

Setup:

  • docker swarm with 7 nodes
  • Service should run on just a single node
  • Only running stacks
  • 64 GB RAM host
  • 32 GB shm (host)
  • Docker version 18.09.7, build 2d0083d
  • Using v 3.7 in my compose file

Compose file:

version: "3.7"
services:
  server:
    shm_size: 16GB # <<<<<<< This fails
    image: local_repo/my_app:v1-dev
    command: run
    environment:
      - UPDATES=enabled
    volumes:
      - type: volume
        source: data
        target: /var/lib/my_app/
      - type: volume
        source: db
        target: /var/lib/postgresql/10/main
    networks:
      - xxx_traefik
    deploy:
     mode: replicated
     labels:
        - traefik.docker.network=xxx_traefik
        - traefik.enable=true
        - traefik.port=80
        - traefik.frontend.rule=Host:my_container.xxx.com
        - traefik.backend.loadbalancer.stickiness=true
        - traefik.protocol=http
     replicas: 1
     placement:
       constraints:
         - node.hostname==node2

volumes:
  db:
   external: true
  data:
   external: true
networks:
  xxx_traefik:
    external: true
# shm_size: 16GB  <<<<<<< Also tried to put it here since documentation doesn't show indents

Any help is appreciated:)

sebas Spotmaster
  • 131
  • 1
  • 1
  • 3

1 Answers1

22

It should be below service, I can verify it, but here is what offical documentation said

SHM_SIZE

Added in version 3.5 file format

Set the size of the /dev/shm partition for this build’s containers. Specify as an integer value representing the number of bytes or as a string expressing a byte value.

build:
  context: .
  shm_size: '2gb'

compose-file-SHM_SIZE

Here is test

version: '3.7'
services:
  your_service:
    image: alpine
    command: ash -c "sleep 2 && df /dev/shm"
    shm_size: 2gb

enter image description here

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • Thanks! I see that that works. I see that I never mentioned it, but I'm using a docker stack deploy to deploy it. In there it says it's ignored. I can't find anything in the docs that mentions that it's ignored like with the other options. Am I wrong or should it also just work in a docker stack deploy? – sebas Spotmaster Nov 20 '19 at 12:54
  • oh then it is issue with docker swarm, according to this issue https://github.com/moby/moby/issues/26714 swarm does not support. but you can check for workaround. to pass it build time – Adiii Nov 20 '19 at 13:16
  • 1
    I see, thanks! The workaround only seems to be for the build, not for the run... – sebas Spotmaster Nov 20 '19 at 15:31
  • 2
    Haha no I needed it for the run part. Found a workaround solution: ``` volumes: - type: tmpfs target: /dev/shm tmpfs: size: 16000000000 #~ 16gb ``` – sebas Spotmaster Nov 20 '19 at 16:09