mirror of https://github.com/docker/docs.git
chore: format document
This commit is contained in:
parent
04c702730d
commit
0de7f57f79
|
@ -3,10 +3,10 @@ description: Using volumes
|
|||
title: Volumes
|
||||
keywords: storage, persistence, data persistence, volumes
|
||||
redirect_from:
|
||||
- /userguide/dockervolumes/
|
||||
- /engine/tutorials/dockervolumes/
|
||||
- /engine/userguide/dockervolumes/
|
||||
- /engine/admin/volumes/volumes/
|
||||
- /userguide/dockervolumes/
|
||||
- /engine/tutorials/dockervolumes/
|
||||
- /engine/userguide/dockervolumes/
|
||||
- /engine/admin/volumes/volumes/
|
||||
---
|
||||
|
||||
Volumes are the preferred mechanism for persisting data generated by and used
|
||||
|
@ -50,6 +50,7 @@ If you need to specify volume driver options, you must use `--mount`.
|
|||
- **`-v` or `--volume`**: Consists of three fields, separated by colon characters
|
||||
(`:`). The fields must be in the correct order, and the meaning of each field
|
||||
is not immediately obvious.
|
||||
|
||||
- In the case of named volumes, the first field is the name of the volume, and is
|
||||
unique on a given host machine. For anonymous volumes, the first field is
|
||||
omitted.
|
||||
|
@ -90,11 +91,10 @@ If you need to specify volume driver options, you must use `--mount`.
|
|||
> --mount 'type=volume,src=<VOLUME-NAME>,dst=<CONTAINER-PATH>,volume-driver=local,volume-opt=type=nfs,volume-opt=device=<nfs-server>:<nfs-path>,"volume-opt=o=addr=<nfs-address>,vers=4,soft,timeo=180,bg,tcp,rw"'
|
||||
> --name myservice \
|
||||
> <IMAGE>
|
||||
> {: .warning}
|
||||
|
||||
{: .warning}
|
||||
|
||||
The examples below show both the `--mount` and `-v` syntax where possible, and
|
||||
`--mount` is presented first.
|
||||
`--mount` is presented first.
|
||||
|
||||
### Differences between `-v` and `--mount` behavior
|
||||
|
||||
|
@ -243,7 +243,9 @@ volumes:
|
|||
external: true
|
||||
```
|
||||
|
||||
For more information about using volumes with Compose, refer to the [Volumes](../compose/compose-file/index.md#volumes) section in the Compose specification.
|
||||
For more information about using volumes with Compose, refer to the
|
||||
[Volumes](../compose/compose-file/index.md#volumes)
|
||||
section in the Compose specification.
|
||||
|
||||
### Start a service with volumes
|
||||
|
||||
|
@ -331,7 +333,6 @@ $ docker run -d \
|
|||
After running either of these examples, run the following commands to clean up
|
||||
the containers and volumes. Note volume removal is a separate step.
|
||||
|
||||
|
||||
```console
|
||||
$ docker container stop nginxtest
|
||||
|
||||
|
@ -463,12 +464,13 @@ $ docker volume create --driver vieux/sshfs \
|
|||
### Start a container which creates a volume using a volume driver
|
||||
|
||||
The following example specifies an SSH password. However, if the two hosts have
|
||||
shared keys configured, you can exclude the password. Each volume driver may have zero or more configurable options.
|
||||
shared keys configured, you can exclude the password.
|
||||
Each volume driver may have zero or more configurable options.
|
||||
|
||||
> **Note:**
|
||||
>
|
||||
> If the volume driver requires you to pass any options, you must use the `--mount` flag to mount the volume, and not `-v`.
|
||||
|
||||
> If the volume driver requires you to pass any options,
|
||||
> you must use the `--mount` flag to mount the volume, and not `-v`.
|
||||
|
||||
```console
|
||||
$ docker run -d \
|
||||
|
@ -480,7 +482,9 @@ $ docker run -d \
|
|||
|
||||
### Create a service which creates an NFS volume
|
||||
|
||||
The following example shows how you can create an NFS volume when creating a service. It uses `10.0.0.10` as the NFS server and `/var/docker-nfs` as the exported directory on the NFS server. Note that the volume driver specified is `local`.
|
||||
The following example shows how you can create an NFS volume when creating a service.
|
||||
It uses `10.0.0.10` as the NFS server and `/var/docker-nfs` as the exported directory on the NFS server.
|
||||
Note that the volume driver specified is `local`.
|
||||
|
||||
#### NFSv3
|
||||
|
||||
|
@ -502,7 +506,8 @@ $ docker service create -d \
|
|||
|
||||
### Create CIFS/Samba volumes
|
||||
|
||||
You can mount a Samba share directly in docker without configuring a mount point on your host.
|
||||
You can mount a Samba share directly in Docker without configuring a mount point on your host.
|
||||
|
||||
```console
|
||||
$ docker volume create \
|
||||
--driver local \
|
||||
|
@ -512,12 +517,13 @@ $ docker volume create \
|
|||
--name cif-volume
|
||||
```
|
||||
|
||||
Notice the `addr` option is required if using a hostname instead of an IP so docker can perform the hostname lookup.
|
||||
The `addr` option is required if you specify a hostname instead of an IP.
|
||||
This lets Docker perform the hostname lookup.
|
||||
|
||||
## Back up, restore, or migrate data volumes
|
||||
|
||||
Volumes are useful for backups, restores, and migrations. Use the
|
||||
`--volumes-from` flag to create a new container that mounts that volume.
|
||||
Volumes are useful for backups, restores, and migrations.
|
||||
Use the `--volumes-from` flag to create a new container that mounts that volume.
|
||||
|
||||
### Back up a volume
|
||||
|
||||
|
@ -542,8 +548,8 @@ the `dbdata` volume.
|
|||
|
||||
### Restore volume from a backup
|
||||
|
||||
With the backup just created, you can restore it to the same container, or to
|
||||
another container that you created elsewhere.
|
||||
With the backup just created, you can restore it to the same container,
|
||||
or to another container that you created elsewhere.
|
||||
|
||||
For example, create a new container named `dbstore2`:
|
||||
|
||||
|
@ -566,7 +572,7 @@ A Docker data volume persists after you delete a container. There are two types
|
|||
of volumes to consider:
|
||||
|
||||
- Named volumes have a specific source from outside the container, for example, `awesome:/bar`.
|
||||
- Anonymous volumes have no specific source, therefore, when the container is deleted, you can instruct the Docker Engine daemon to remove them.
|
||||
- Anonymous volumes have no specific source. Therefore, when the container is deleted, you can instruct the Docker Engine daemon to remove them.
|
||||
|
||||
### Remove anonymous volumes
|
||||
|
||||
|
|
Loading…
Reference in New Issue