10

I know is possible to increase default 64MB /dev/shm in docker container from docker run or docker compose. As example this works in our local development machines.

version: '3.5'
services:
  postgres:
    image: postgres
    shm_size: '1gb'

However when I try to do it in our swarm docker stack deploy stack_name -c docker-compose.yml I get a "Ignoring unsupported options: shm_size" and shm mount remains as default 64MB.

What can I do? I tried to create an image with this parameter but it seems is not something that I can add to image built, more like a runtime option. It's possible to modify it after container creation?

Environment is an Ubuntu 16.04 with docker 17.12 in a single node swarm.

Gonzalo Cao
  • 2,286
  • 1
  • 24
  • 20

3 Answers3

12

You can add the following code in docker-compose.yml. It will directly add a tmpfs volume targetting /dev/shm:

volumes:
      - type: tmpfs
        target: /dev/shm
        tmpfs:
           size: 4096000000 # (this means 4GB)
Tony Qu
  • 676
  • 8
  • 14
6

You need to use a more recent version of Docker Compose. The latest version (docker-compose version 1.24.0, build 0aa5906) certainly supports it.

The above answer was assuming Docker Compose, but docker swarm is not the same thing at all. docker swarm does not yet support shm_size in the configuration file, but does seem to have workarounds.

l0b0
  • 55,365
  • 30
  • 138
  • 223
  • 1
    It still doesn't work with the latest version ( the one in your answer ). After running this command `docker stack deploy --compose-file docker-compose.swarm.yml my_stack` I have the following warning: `Ignoring unsupported options: shm_size` – HereHere Jul 02 '19 at 11:08
3

I found solution for docker swarm:

postgres:
  image: postgres:11-alpine
  shm_size: "512M"
  command: >
    postgres
    -c shared_preload_libraries='pg_stat_statements'
    -c pg_stat_statements.track=all
    -c max_connections=200
    -c shared_buffers=256MB
    -c statement_timeout=1800000
  ports:
    - 5432:5432
  environment:
    POSTGRES_DB: my_db
    POSTGRES_PASSWORD: 123123
    POSTGRES_USER: my_user
    TZ: "Europe/Moscow"
  tmpfs:
    - /tmp:size=512M
  volumes:
  - /etc/localtime:/etc/localtime:ro
  - type: tmpfs
    target: /dev/shm
  networks:
    - default
vitams
  • 585
  • 6
  • 7