docker SHM_SIZE / dev / shm:调整共享内存的大小 [英] docker SHM_SIZE /dev/shm: resizing shared memory

查看:2554
本文介绍了docker SHM_SIZE / dev / shm:调整共享内存的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从默认的 64M 调整 postgres 容器的共享内存大小。因此,我添加:

I want to resize postgres container's shared memory from default 64M. So I add:

build:
      context: .
      shm_size: '2gb'

我正在使用撰写文件的版本3.6, postgres 服务定义。

I'm using version 3.6 of the compose file, postgres service definition.

version: "3.6"

services:

 #other services go here..
 postgres:
    restart: always
    image: postgres:10
    hostname: postgres
    container_name: fiware-postgres
    expose:
      - "5432"
    ports:
      - "5432:5432"
    networks:
      - default
    environment:
      - "POSTGRES_PASSWORD=password"
      - "POSTGRES_USER=postgres"
      - "POSTGRES_DB=postgres"
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    build:
      context: .
      shm_size: '2gb'

但是,即使我重新启动服务 docker-compose down ,然后 up 。因此,我立即开始与postgres进行交互以在仪表板上显示一些数据,但出现共享内存问题。

However, this change doesn't take effect even though I restart the service docker-compose down then up. So Immediately I start interacting with postgres to display some data on dashboard, I get shared memory issue.

在仪表板吃午饭之前:

$docker exec -it fiware-postgres df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-107615-1541c55e4c3d5e03a7716d5418eea4c520b6556a6fd179c6ab769afd0ce64d9f   10G  266M  9.8G   3% /
tmpfs                                                                                              64M     0   64M   0% /dev
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/vda1                                                                                         197G   52G  136G  28% /etc/hosts
shm                                                                                                64M  8.0K   64M   1% /dev/shm
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/acpi
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/scsi
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/firmware

午餐后仪表板:

$docker exec -it fiware-postgres df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-107615-1541c55e4c3d5e03a7716d5418eea4c520b6556a6fd179c6ab769afd0ce64d9f   10G  266M  9.8G   3% /
tmpfs                                                                                              64M     0   64M   0% /dev
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/vda1                                                                                         197G   52G  136G  28% /etc/hosts
shm                                                                                                64M   50M   15M  78% /dev/shm
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/acpi
tmpfs                                                                                             1.4G     0  1.4G   0% /proc/scsi
tmpfs                                                                                             1.4G     0  1.4G   0% /sys/firmware

postgres错误日志:

postgres error log:

2019-07-01 17:27:58.802 UTC [47] ERROR:  could not resize shared memory segment "/PostgreSQL.1145887853" to 12615680 bytes: No space left on device

这是怎么回事?

推荐答案

您在 build 中设置了 shm_size ,这只会影响构建,您需要将其设置为服务级别,例如:

You set shm_size in build, this will just affect build, you need to set it in service level, like next:

docker-compose.yaml:

version: "3.6"

services:

 #other services go here..
 postgres:
    restart: always
    image: postgres:10
    hostname: postgres
    container_name: fiware-postgres
    expose:
      - "5432"
    ports:
      - "5432:5432"
    networks:
      - default
    environment:
      - "POSTGRES_PASSWORD=password"
      - "POSTGRES_USER=postgres"
      - "POSTGRES_DB=postgres"
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    build:
      context: .
      shm_size: 256mb
    shm_size: 512mb

Dockerfile: b strong>

Dockerfile:

FROM postgres:10

RUN df -h | grep shm

然后, docker-compose up -d --build 启动并检查:

shubuntu1@shubuntu1:~/66$ docker-compose --version
docker-compose version 1.24.0, build 0aa59064
shubuntu1@shubuntu1:~/66$ docker-compose up -d --build
Building postgres
Step 1/2 : FROM postgres:10
 ---> 0959974989f8
Step 2/2 : RUN df -h | grep shm
 ---> Running in 25d341cfde9c
shm             256M     0  256M   0% /dev/shm
Removing intermediate container 25d341cfde9c
 ---> 1637f1afcb81

Successfully built 1637f1afcb81
Successfully tagged postgres:10
Recreating fiware-postgres ... done
shubuntu1@shubuntu1:~/66$ docker exec -it fiware-postgres df -h | grep shm
shm             512M  8.0K  512M   1% /dev/shm

生成时间显示 256m ,但是运行时容器显示 512m

You can see in build time it shows 256m, but the runtime container it shows 512m.

这篇关于docker SHM_SIZE / dev / shm:调整共享内存的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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