docker SHM_SIZE /dev/shm: resizing shared memory

て烟熏妆下的殇ゞ 提交于 2020-08-05 04:17:27

问题


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

build:
      context: .
      shm_size: '2gb'

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'

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.

Before lunching the dashboard:

$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

After lunching the dashboard:

$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 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

What's going on here?


回答1:


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:

FROM postgres:10

RUN df -h | grep shm

Then, docker-compose up -d --build to start it and check:

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

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



来源:https://stackoverflow.com/questions/56839975/docker-shm-size-dev-shm-resizing-shared-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!