Skip to content

Commit 857b9af

Browse files
authored
Merge pull request #21676 from dvdksn/tmpfs-default-mountopts
storage: document opts with --tmpfs
2 parents c41ed45 + dc28d62 commit 857b9af

File tree

1 file changed

+70
-9
lines changed

1 file changed

+70
-9
lines changed

content/manuals/engine/storage/tmpfs.md

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,67 @@ $ docker run --tmpfs <mount-path>
6060
```
6161

6262
In general, `--mount` is preferred. The main difference is that the `--mount`
63-
flag is more explicit and supports all the available options.
63+
flag is more explicit. On the other hand, `--tmpfs` is less verbose and gives
64+
you more flexibility as it lets you set more mount options.
6465

6566
The `--tmpfs` flag cannot be used with swarm services. You must use `--mount`.
6667

68+
### Options for --tmpfs
69+
70+
The `--tmpfs` flag consists of two fields, separated by a colon character
71+
(`:`).
72+
73+
```console
74+
$ docker run --tmpfs <mount-path>[:opts]
75+
```
76+
77+
The first field is the container path to mount into a tmpfs. The second field
78+
is optional and lets you set mount options. Valid mount options for `--tmpfs`
79+
include:
80+
81+
| Option | Description |
82+
| ------------ | ------------------------------------------------------------------------------------------- |
83+
| `ro` | Creates a read-only tmpfs mount. |
84+
| `rw` | Creates a read-write tmpfs mount (default behavior). |
85+
| `nosuid` | Prevents `setuid` and `setgid` bits from being honored during execution. |
86+
| `suid` | Allows `setuid` and `setgid` bits to be honored during execution (default behavior). |
87+
| `nodev` | Device files can be created but are not functional (access results in an error). |
88+
| `dev` | Device files can be created and are fully functional. |
89+
| `exec` | Allows the execution of executable binaries in the mounted file system. |
90+
| `noexec` | Does not allow the execution of executable binaries in the mounted file system. |
91+
| `sync` | All I/O to the file system is done synchronously. |
92+
| `async` | All I/O to the file system is done asynchronously (default behavior). |
93+
| `dirsync` | Directory updates within the file system are done synchronously. |
94+
| `atime` | Updates file access time each time the file is accessed. |
95+
| `noatime` | Does not update file access times when the file is accessed. |
96+
| `diratime` | Updates directory access times each time the directory is accessed. |
97+
| `nodiratime` | Does not update directory access times when the directory is accessed. |
98+
| `size` | Specifies the size of the tmpfs mount, for example, `size=64m`. |
99+
| `mode` | Specifies the file mode (permissions) for the tmpfs mount (for example, `mode=1777`). |
100+
| `uid` | Specifies the user ID for the owner of the tmpfs mount (for example, `uid=1000`). |
101+
| `gid` | Specifies the group ID for the owner of the tmpfs mount (for example, `gid=1000`). |
102+
| `nr_inodes` | Specifies the maximum number of inodes for the tmpfs mount (for example, `nr_inodes=400k`). |
103+
| `nr_blocks` | Specifies the maximum number of blocks for the tmpfs mount (for example, `nr_blocks=1024`). |
104+
105+
```console {title="Example"}
106+
$ docker run --tmpfs /data:noexec,size=1024,mode=1777
107+
```
108+
109+
Not all tmpfs mount features available in the Linux mount command are supported
110+
with the `--tmpfs` flag. If you require advanced tmpfs options or features, you
111+
may need to use a privileged container or configure the mount outside of
112+
Docker.
113+
114+
> [!CAUTION]
115+
> Running containers with `--privileged` grants elevated permissions and can
116+
> expose the host system to security risks. Use this option only when
117+
> absolutely necessary and in trusted environments.
118+
119+
```console
120+
$ docker run --privileged -it debian sh
121+
/# mount -t tmpfs -o <options> tmpfs /data
122+
```
123+
67124
### Options for --mount
68125

69126
The `--mount` flag consists of multiple key-value pairs, separated by commas
@@ -86,10 +143,6 @@ Valid options for `--mount type=tmpfs` include:
86143
$ docker run --mount type=tmpfs,dst=/app,tmpfs-size=21474836480,tmpfs-mode=1770
87144
```
88145

89-
### Options for --tmpfs
90-
91-
The `--tmpfs` flag does not let you specify any options.
92-
93146
## Use a tmpfs mount in a container
94147

95148
To use a `tmpfs` mount in a container, use the `--tmpfs` flag, or use the
@@ -109,6 +162,14 @@ $ docker run -d \
109162
nginx:latest
110163
```
111164

165+
Verify that the mount is a `tmpfs` mount by looking in the `Mounts` section of
166+
the `docker inspect` output:
167+
168+
```console
169+
$ docker inspect tmptest --format '{{ json .Mounts }}'
170+
[{"Type":"tmpfs","Source":"","Destination":"/app","Mode":"","RW":true,"Propagation":""}]
171+
```
172+
112173
{{< /tab >}}
113174
{{< tab name="`--tmpfs`" >}}
114175

@@ -120,17 +181,17 @@ $ docker run -d \
120181
nginx:latest
121182
```
122183

123-
{{< /tab >}}
124-
{{< /tabs >}}
125-
126184
Verify that the mount is a `tmpfs` mount by looking in the `Mounts` section of
127185
the `docker inspect` output:
128186

129187
```console
130188
$ docker inspect tmptest --format '{{ json .Mounts }}'
131-
[{"Type":"tmpfs","Source":"","Destination":"/app","Mode":"","RW":true,"Propagation":""}]
189+
{"/app":""}
132190
```
133191

192+
{{< /tab >}}
193+
{{< /tabs >}}
194+
134195
Stop and remove the container:
135196

136197
```console

0 commit comments

Comments
 (0)