Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the size of the /dev/shm in docker container

Currently When I create new docker container the size of the shared memory directory is limited to 64MB. But, I need to increase this size since my application depend on this shared memory. Is there any way to increase the size of /dev/shm in docker container? I heard that the 64MB is hard coded in the docker code, How to install docker from source and change the value of the /dev/shm?

like image 972
user2521791 Avatar asked May 13 '15 09:05

user2521791


People also ask

What is SHM size in Docker?

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


3 Answers

If you're using docker-compose, you can set the your_service.shm_size value if you want your container to use that /dev/shm size when running or your_service.build.shm_size when building.

Example:

version: '3.5'
services:
  your_service:
    build:
      context: .
      shm_size: '2gb' <-- this will set the size when BUILDING
    shm_size: '2gb' <-- when RUNNING 

Link to source.

like image 62
Diego M.F. Avatar answered Oct 17 '22 04:10

Diego M.F.


You can modify shm size by passing the optional parameter --shm-size to docker run command. The default is 64MB.

eg:

docker run -it --shm-size=256m oracle11g /bin/bash
like image 96
Lijo Jacob Avatar answered Oct 17 '22 06:10

Lijo Jacob


If you use docker-compose to set up your docker environment, it is also possible to set the shared memory in the docker-compose.yml configuration file:

build:
  context: .
  shm_size: '2gb'

More info in the compose-file docs:

  • version 3
  • version 2
like image 15
Jørgen Sivesind Avatar answered Oct 17 '22 06:10

Jørgen Sivesind