You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To mount a host directory into a container, create the container with a `HostConfig`.
532
576
You can set the local path and remote path in the `binds()` method on the `HostConfig.Builder`.
533
577
There are two ways to make a bind:
534
578
1. Pass `binds()` a set of strings of the form `"local_path:container_path"` for read/write or `"local_path:container_path:ro"` for read only.
535
579
2. Create a `Bind` object and pass it to `binds()` (or `appendBinds()` if you want to incrementally add multiple `Bind`s).
536
580
537
-
If you only need to create a volume to be mounted in a container, but you don't need it to be bound to any
538
-
particular directory on the host, you can use the `volumes()` method on the
539
-
`ContainerConfig.Builder`.
581
+
When you create a `Bind`, you are making a connection from outside the container to inside; as such, you must give a `Bind` object a `from` and a `to`. `from` can be given either by a `String` containing the path to a local file or directory, or a pre-existing `Volume` object. `to` must be a `String` containing the path to be bound inside the container.
582
+
583
+
If you only need to create a volume to be mounted in a container, but you don't need it to be bound to any particular directory on the host, you can use the `ContainerConfig.Builder.volumes("/path")` method. The path you give to this method will be created inside the container, but does not correspond to anything outside.
540
584
541
585
```java
542
586
finalHostConfig hostConfig =
@@ -546,6 +590,10 @@ final HostConfig hostConfig =
546
590
.to("/another/remote/path")
547
591
.readOnly(true)
548
592
.build())
593
+
.appendBinds(Bind.from(aVolume)
594
+
.to("/yet/another/remote/path")
595
+
.readOnly(false)
596
+
.build())
549
597
.build();
550
598
finalContainerConfig volumeConfig =
551
599
ContainerConfig.builder()
@@ -555,7 +603,7 @@ final ContainerConfig volumeConfig =
555
603
.build();
556
604
```
557
605
558
-
####A note on mounts
606
+
### A note on mounts
559
607
Be aware that, starting with API version 1.20 (docker version 1.8.x), information
560
608
about a container's volumes is returned with the key `"Mounts"`, not `"Volumes"`.
561
609
As such, the `ContainerInfo.volumes()` method is deprecated. Instead, use
0 commit comments