Docker 数据管理-Volumes
Volumes是Docker最为推荐的数据持久化方法。
Volumes have several advantages over bind mounts:
- Volumes are easier to back up or migrate than bind mounts.
- You can manage volumes using Docker CLI commands or the Docker API.
- Volumes work on both Linux and Windows containers.
- Volumes can be more safely shared among multiple containers.
- Volume drivers allow you to store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.
- A new volume’s contents can be pre-populated by a container.
Choose the -v or --mount flag
起初, the -v
or --volume
flag was used for 单机版-Containers and the --mount
flag was used for Swarm services. However, starting with Docker 17.06, you can also use --mount
with 单机版-Containers. In general, --mount
更清晰 and 更冗长. 最大的不同是 -v
语法将所有的选项组合在一起,--mount语法将他们进行了分离。
Tip: 新永不应该使用--mount语法,有经验的用户更熟悉-v or --volume语法。 但是更鼓励使用--mount,因为调查发现它更容易被使用。
If you need to specify volume driver options, you must use --mount
.
--mount
: 由多个<key>=<value>对组成,使用逗号进行分割。The--mount
syntax is more verbose than-v
or--volume
, but the order of the keys is not significant, and the value of the flag is easier to understand.- The
type
of the mount, which can bebind
,volume
, ortmpfs
. This topic discusses volumes, so the type is alwaysvolume
. - The
source
of the mount. For named volumes, this is the name of the volume. For anonymous volumes, this field is omitted. May be specified assource
orsrc
. - The
destination
takes as its value the path where the file or directory is mounted in the container. May be specified asdestination
,dst
, ortarget
. - The
readonly
option, if present, causes the bind mount to be mounted into the container as read-only. - The
volume-opt
option, which can be specified more than once, takes a key-value pair consisting of the option name and its value.
- The
Create and manage volumes
Unlike a bind mount, you can create and manage volumes outside the scope of any container.
Create a volume:
$ docker volume create my-vol
List volumes:
$ docker volume ls
local my-vol
Inspect a volume:
$ docker volume inspect my-vol
[
{
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/my-vol/_data",
"Name": "my-vol",
"Options": {},
"Scope": "local"
}
]
Remove a volume:
$ docker volume rm my-vol
Start a container with a volume
If you start a container with a volume that does not yet exist, Docker creates the volume for you. The following example mounts the volume myvol2
into /app/
in the container.
The -v
and --mount
examples below produce the same result. You can’t run them both unless you remove the devtest
container and the myvol2
volume after running the first one.
$ docker run -d \
--name devtest \
--mount source=myvol2,target=/app \
nginx:latest
$ docker run -d \
--name devtest \
-v myvol2:/app \
nginx:latest
- 可以为多个Container mount同一个volume,以达到数据在多个Container之间共享的目的;
- 如果 mount target指向的是已有目录,原有数据会被复制到source volume 中。
参考文档: https://docs.docker.com/
Docker 数据管理-Volumes的更多相关文章
- Docker数据管理
用户在使用Docker的过程中,往往需要能查看容器内应用产生的数据,或者需要把容器内的数据进行备份,甚至多个容器之间进行数据共享,这必然涉及到Docker的数据管理. 容器中管理数据主要有两种方式: ...
- Docker数据管理(四)
Docker数据管理 Docker数据分为两种: 数据卷 -v /data -v src:dst 数据卷容器 --volumes-from 数据卷 案例1:我们创建一个容器,起名叫nginx-volu ...
- Docker 数据管理(Volumes)
Docker 容器产生的数据在可写层,如果不通过 docker commit 生成新的镜像,使得数据成为镜像的一部分保存下来,那么当容器删除后,数据自然也就没有了. Docker 提供了三种数据 Mo ...
- Docker数据管理-数据卷 data volumes和数据卷容器data volumes containers的使用详解
此文来源于:https://yq.aliyun.com/ziliao/43471 参考原文件之外,做了些修改. Volume数据卷是Docker的一个重要概念.数据卷是可供一个或多个容器使用的特殊目录 ...
- Docker系统七:Docker数据管理
Docker的数据管理 I. 基本概念 Docker容器一旦删除,其相关的rootf文件系统就会被删除,其容器内的数据将一并删除,为了保存相关数据,Docker提出了数据卷的概念. II. 数据卷 D ...
- Docker数据管理(数据卷&数据卷容器)
生产环境中使用Docker的过程中,往往需要对数据进行持久化,或者需要在多个容器之间进行数据共享,这必然涉及容器的数据管理操作. 容器中管理数据主要有两种方式: 数据卷(Data Volumes):容 ...
- 【Docker】第五篇 Docker 数据管理
一.基本介绍 数据管理的原因:Docker中的容器一旦删除,容器本身的rootfs文件系统就会被删除,容器中的所有数据就会被删除.为了对一些需要持久化的数据,不随容器删除而删除,所以我们可以通过多个容 ...
- 六、【Docker笔记】Docker数据管理
前几节我们介绍了Docker的基本使用和三大核心概念,那么我们在使用Docker的过程中,Docker中必然产生了大量的数据,对于这些数据我们需要查看或者对这些数据进行一个备份,也有可能容器之间的数据 ...
- Docker数据管理(五)
一.什么是数据卷 生成环境中使用docker的过程中,往往需要对数据进行持久化,或者需要多个容器之间进行数据共享,这个就涉及到了容器数据管理 容器中管理数据主要有两种方式: 数据卷:容器内数据之间映射 ...
随机推荐
- asp.net repeater Container.ItemIndex
<asp:Repeater ID="myRepeater" runat="server"> <HeaderTemplate> <t ...
- const_cast去除const限制,同一片内存
本质很简单,但一些优化 和 编程上的错误,却让人看不清本质. :const_cast<type_id> (expression) 该运算符用来修改类型的const或volatile属性.除 ...
- 一个可以模拟GET,POST,PUT,DELET请求的HTTP在线工具
一个简陋的HTTP请求工具,UI比较丑陋.0.0,可以用于接口调试. 之前在调试公司的远程接口的时候用的是curl,后来也在网上找到几种Http请求模拟的客户端程序.当时后来发现google app ...
- iOS tableView嵌套部分WebView效果实现
对于一些资讯类的app,比如网易新闻,今日头条这样的,他们的文章详情页大部分基本都是tableView中嵌套webView来实现的效果,其中顶部标题,关注按钮等这些可能是原生的,内容部分是webVie ...
- openWRT自学---对官方的开发指导文档的解读和理解 记录2:如何控制内核模块的编译
openwrt对于kernel module的处理分两类:随内核主线而来的kernel module 和 其他作为独立project的kernel module.而这两种,openwrt将采用相同的模 ...
- spring roo反向工程
1.创建spring roo工程 2.在数据库中创建数据库feedback_schema,再创建几张表 3.创建连接数据库 persistence setup --provider HIBER ...
- 关于IIS上Yii2的Url路由美化
Yii2默认的路由是酱紫的 http://.../admin/web/index.php?r=site/login 心中理想的美化Url应该这样 http://.../admin/web/site/ ...
- Python中使用__new__实现单例模式并解析
阅读文章前请先阅读 Python中类方法.__new__方法和__init__方法解析 单例模式是一个经典设计模式,简要的说,一个类的单例模式就是它只能被实例化一次,实例变量在第一次实例化时就已经固定 ...
- tomcat日志按天切分
1. 下载工具cronolog wget http://cronolog.org/download/cronolog-1.6.2.tar.gz 这是网上流传的下载地址,好像没用,所以需要自己去网上找. ...
- swift 一句代码补全tableView分割线
1.swift实现分割线补全 swift一个大进步,只要设置tableView.separatorInset = UIEdgeInsets.zero即可补全分割线, 2.OC实现分割线补全 而在OC中 ...