Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing shared memory size in docker compose

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:)

like image 863
sebas Spotmaster Avatar asked Nov 20 '19 10:11

sebas Spotmaster


People also ask

How do I change the memory limit on a docker container?

To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.

What is the default size of shared memory in Docker container?

Docker containers are allocated 64 MB of shared memory by default.

What is MEM limit in Docker compose?

Before getting into mem_limit docker compose let us take a look at mem_limit. Memory Limit or mem-limit, in general, imposes an upper limit on the amount of memory that a Docker container can potentially use.

How much memory should I allocate to Docker?

The minimum allowed value is 4m . Because kernel memory cannot be swapped out, a container which is starved of kernel memory may block host machine resources, which can have side effects on the host machine and on other containers.


1 Answers

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

like image 122
Adiii Avatar answered Sep 23 '22 12:09

Adiii