Is there a way to set the size of /dev/shm globally so the --shm-size flag doesn't need to be set as part of docker run?

Viewed 1506

I would like to be able to have /dev/shm preset to a different value than 64 MB, so that any container I spin up automatically takes on that new value.

I know I can run

docker run --shm-size=2G some-container

but i'd like to be able to do this without having to add the --shm-size flag. Is this possible?

1 Answers

You can set default value in /etc/docker/daemon.json:

shubuntu1@shubuntu1:/etc/docker$ cat daemon.json
{
    "default-shm-size": "1G"
}

If do not have this file, you can new a file and add configure to it.

After modify, restart docker service:

sudo systemctl restart docker

Then, confirm it with next command:

shubuntu1@shubuntu1:/etc/docker$ docker run --rm -it ubuntu df -h | grep shm
shm             1.0G     0  1.0G   0% /dev/shm

You can see shared memory already set as 1G just the value you set in daemon.json, detail refers to official guide.

Related