在Docker中更改共享内存的大小 [英] Changing shared memory size in docker compose

查看:203
本文介绍了在Docker中更改共享内存的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在一个容器中的共享内存出现了一些问题.

我有一个docker-compose文件,希望可以在其中设置大小.我基本上转换了一个旧的docker run,该运行具有-shm-size 16gb .我想这就像将 shm_size:16gb 添加到撰写文件中的服务一样简单.

添加它只会给我以下信息:忽略不支持的选项:shm_size .

我确实检查了

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

解决方案

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

这篇关于在Docker中更改共享内存的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆