Skip to content

Commit e1e95ec

Browse files
committed
Update docs
1 parent 7b57f3a commit e1e95ec

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

docs/user_manual.md

+53-5
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,60 @@ docker.execResizeTty("execID", height, width);
527527

528528
See [example above](#exec-create).
529529

530-
### Mounting directories in a container
530+
## Volumes
531+
532+
### List volumes
533+
534+
```java
535+
final VolumeList volumeList = docker.listVolumes();
536+
final List<String> warnings = volumeList.warnings();
537+
final List<Volume> volumes = volumeList.volumes();
538+
```
539+
540+
### Create a volume
541+
Create a volume with specified properties:
542+
```java
543+
final Volume toCreate = Volume.builder()
544+
.name("volumeName")
545+
.driver("local")
546+
.labels(ImmutableMap.of("foo", "bar"))
547+
.build();
548+
final Volume created = docker.createVolume(toCreate);
549+
```
550+
551+
Or create an anonymous volume:
552+
```java
553+
final Volume created = docker.createVolume();
554+
```
555+
556+
### Inspect a volume
557+
558+
```java
559+
final Volume volume = docker.inspectVolume("volumeName");
560+
```
561+
562+
### Remove a volume
563+
By name
564+
```java
565+
docker.removeVolume("volumeName");
566+
```
567+
568+
Or by object reference
569+
```java
570+
docker.removeVolume(volume);
571+
```
572+
573+
# Going Further
574+
## Mounting directories in a container
531575
To mount a host directory into a container, create the container with a `HostConfig`.
532576
You can set the local path and remote path in the `binds()` method on the `HostConfig.Builder`.
533577
There are two ways to make a bind:
534578
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.
535579
2. Create a `Bind` object and pass it to `binds()` (or `appendBinds()` if you want to incrementally add multiple `Bind`s).
536580

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.
540584

541585
```java
542586
final HostConfig hostConfig =
@@ -546,6 +590,10 @@ final HostConfig hostConfig =
546590
.to("/another/remote/path")
547591
.readOnly(true)
548592
.build())
593+
.appendBinds(Bind.from(aVolume)
594+
.to("/yet/another/remote/path")
595+
.readOnly(false)
596+
.build())
549597
.build();
550598
final ContainerConfig volumeConfig =
551599
ContainerConfig.builder()
@@ -555,7 +603,7 @@ final ContainerConfig volumeConfig =
555603
.build();
556604
```
557605

558-
#### A note on mounts
606+
### A note on mounts
559607
Be aware that, starting with API version 1.20 (docker version 1.8.x), information
560608
about a container's volumes is returned with the key `"Mounts"`, not `"Volumes"`.
561609
As such, the `ContainerInfo.volumes()` method is deprecated. Instead, use

0 commit comments

Comments
 (0)