Jay Taylor's notesback to listing index
I Just Learnt About /dev/shm • Son Dang[web search]
I Just Learnt About /dev/shm
This morning I went to a tech talk organized by Grokking Vietnam.
The talk was about using Docker and Selenium in End-to-End testing, which was a pretty interesting topic.
In the middle of the talk, the speaker introduced a
docker-compose.yml file with a noticeable line:
# docker-compose.yml version: '3' # ... chrome: # ... volumes: - '/dev/shm:dev/shm' # this line ^^ #...
Here he was trying to run test cases with Selenium webdriver on Docker. The chrome container is for running Google Chrome container in headless mode.
The speaker then asked the audience to explain why we need the
Some people including me tried to answer. I actually thought the shm was meant for Selenium Hub Management.
Finally, no one was able to give a correct answer and as the speaker explained the
/dev/shm was meant for shared memory. Sometimes when the application running inside a Docker container consumes too much memory space, it has to be configured to access the host’s shared memory.
After a dive into Google (Google is my best friend), here is what I discovered:
/dev/shmis an implementation of shared memory concept. What is a shared memory? Shared memory is memory that may be accessed by multiple programs. It is efficient for passing data between programs.
You can check the size of Linux’s shared memory by using this command:
$ df /dev/shm
/dev/shmseems to be Linux specific. On OSX, if you want to create a shared memory, check this Stack Overflow answer
On Linux, to change the size of
/dev/shm, run this:
$ mount -o remount,size=2G /dev/shm
This command literally means “Remount the /dev/shm with the size of 2GB”.
To run Docker with a custom shared memory size, use the
--shm-sizeoption. For example:
$ docker run -it --shm-size=256m <CONTAINER_NAME> /bin/sh
According to this docs (look for
--shm-size), its default is 64MB.
These are pretty much what I found today. Joining tech talk plus doing a bit of research seems to be a pretty useful learning method.