Visitar URL original
update bind-mount docs · docker/cli@e423deb · GitHub
Skip to content

Commit e423deb

Browse files
committed
update bind-mount docs
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
1 parent 372bbb2 commit e423deb

3 files changed

Lines changed: 52 additions & 8 deletions

File tree

‎docs/reference/commandline/service_create.md‎

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,34 @@ volumes in a service:
363363
<td></td>
364364
<td>
365365
<p>The Engine mounts binds and volumes <tt>read-write</tt> unless <tt>readonly</tt> option
366-
is given when mounting the bind or volume.
366+
is given when mounting the bind or volume. Note that setting <tt>readonly</tt> for a
367+
bind-mount does not make its submounts <tt>readonly</tt> on the current Linux implementation. See also <tt>bind-nonrecursive</tt>.
367368
<ul>
368369
<li><tt>true</tt> or <tt>1</tt> or no value: Mounts the bind or volume read-only.</li>
369370
<li><tt>false</tt> or <tt>0</tt>: Mounts the bind or volume read-write.</li>
370371
</ul></p>
371372
</td>
372373
</tr>
374+
</table>
375+
376+
#### Options for Bind Mounts
377+
378+
The following options can only be used for bind mounts (`type=bind`):
379+
380+
381+
<table>
382+
<tr>
383+
<th>Option</th>
384+
<th>Description</th>
385+
</tr>
386+
<tr>
387+
<td><b>bind-propagation</b></td>
388+
<td>
389+
<p>See the <a href="#bind-propagation">bind propagation section</a>.</p>
390+
</td>
391+
</tr>
373392
<tr>
374393
<td><b>consistency</b></td>
375-
<td></td>
376394
<td>
377395
<p>The consistency requirements for the mount; one of
378396
<ul>
@@ -384,9 +402,24 @@ volumes in a service:
384402
</p>
385403
</td>
386404
</tr>
405+
<tr>
406+
<td><b>bind-nonrecursive</b></td>
407+
<td>
408+
By default, submounts are recursively bind-mounted as well. However, this behavior can be confusing when a
409+
bind mount is configured with <tt>readonly</tt> option, because submounts are not mounted as read-only.
410+
Set <tt>bind-nonrecursive</tt> to disable recursive bind-mount.<br />
411+
<br />
412+
A value is optional:<br />
413+
<br />
414+
<ul>
415+
<li><tt>true</tt> or <tt>1</tt>: Disables recursive bind-mount.</li>
416+
<li><tt>false</tt> or <tt>0</tt>: Default if you do not provide a value. Enables recursive bind-mount.</li>
417+
</ul>
418+
</td>
419+
</tr>
387420
</table>
388421

389-
#### Bind Propagation
422+
##### Bind propagation
390423

391424
Bind propagation refers to whether or not mounts created within a given
392425
bind mount or named volume can be propagated to replicas of that mount. Consider
@@ -423,7 +456,7 @@ volumes do not support bind propagation.
423456
For more information about bind propagation, see the
424457
[Linux kernel documentation for shared subtree](https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt).
425458

426-
#### Options for Named Volumes
459+
#### Options for named volumes
427460

428461
The following options can only be used for named volumes (`type=volume`):
429462

@@ -459,9 +492,9 @@ The following options can only be used for named volumes (`type=volume`):
459492
the Engine copies those files and directories into the volume, allowing
460493
the host to access them. Set <tt>volume-nocopy</tt> to disable copying files
461494
from the container's filesystem to the volume and mount the empty volume.<br />
462-
463-
A value is optional:
464-
495+
<br />
496+
A value is optional:<br />
497+
<br />
465498
<ul>
466499
<li><tt>true</tt> or <tt>1</tt>: Default if you do not provide a value. Disables copying.</li>
467500
<li><tt>false</tt> or <tt>0</tt>: Enables copying.</li>

‎man/docker-run.1.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,18 @@ according to RFC4862.
453453

454454
* `src`, `source`: mount source spec for `bind` and `volume`. Mandatory for `bind`.
455455
* `dst`, `destination`, `target`: mount destination spec.
456-
* `ro`, `read-only`: `true` or `false` (default).
456+
* `ro`, `readonly`: `true` or `false` (default).
457+
458+
**Note**: setting `readonly` for a bind mount does not make its submounts
459+
read-only on the current Linux implementation. See also `bind-nonrecursive`.
457460

458461
Options specific to `bind`:
459462

460463
* `bind-propagation`: `shared`, `slave`, `private`, `rshared`, `rslave`, or `rprivate`(default). See also `mount(2)`.
461464
* `consistency`: `consistent`(default), `cached`, or `delegated`. Currently, only effective for Docker for Mac.
465+
* `bind-nonrecursive`: `true` or `false` (default). If set to `true`,
466+
submounts are not recursively bind-mounted. This option is useful for
467+
`readonly` bind mount.
462468

463469
Options specific to `volume`:
464470

‎opts/mount.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func (m *MountOpt) Set(value string) error {
103103
mount.Consistency = mounttypes.Consistency(strings.ToLower(value))
104104
case "bind-propagation":
105105
bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
106+
case "bind-nonrecursive":
107+
bindOptions().NonRecursive, err = strconv.ParseBool(value)
108+
if err != nil {
109+
return fmt.Errorf("invalid value for %s: %s", key, value)
110+
}
106111
case "volume-nocopy":
107112
volumeOptions().NoCopy, err = strconv.ParseBool(value)
108113
if err != nil {

0 commit comments

Comments
 (0)