7

When deploying a standalone container I can mount /dev/shm as a tmpfs with custom options as follows:

docker run --name my-container -v /dev/shm --tmpfs /dev/shm:rw,nosuid,nodev,exec,size=90g my-image

However, I cannot figure out how to do the same thing when deploying a container over a swarm using docker stack deploy. There does not appear to be any relevant information in the documentation here. With the following docker-compose.yml

version: '3.6'
services:
  master:
  image: "my-image"
  ports:
   - "8080:8080"
  volumes:
   - type: tmpfs
     target: /dev/shm

/dev/shm is mounted with default options. How can I mount /dev/shm with the options (rw,nosuid,nodev,exec,size=90g) using docker stack deploy?

aht
  • 117
  • 1
  • 7
  • I know this question is old, but were you able to solve it? I am using docker swarm and I am running jenkins in the swarm. I want my workspace folder to be tmpfs for performance reasons and to avoid disk I/O (because ssd disks do not like to much write operations). But my build job wants to execute nodeJS in workspace what is currently not possible. – tigu Dec 06 '19 at 12:06

1 Answers1

5

Reading the docs here, --tmpfs can only be used with standalone containers, for services use --mount:

--tmpfs: Mounts a tmpfs mount without allowing you to specify any configurable options, and can only be used with standalone containers

Difference between --tmpfs and --mount described here:

  • The --tmpfs flag does not allow you to specify any configurable options.

  • The --tmpfs flag cannot be used with swarm services. You must use --mount.

Community
  • 1
  • 1
namokarm
  • 668
  • 1
  • 7
  • 20
  • Thanks, but I think --mount is a command line parameter only and does not work when using a compose file (or at least is not documented). Furthermore, from the PR [here](https://github.com/moby/moby/pull/36720) it appears that it is not possible to mount a tmpfs with the exec option when using `--mount` – aht May 10 '18 at 17:27