Docker-3:Data Volume
Sometimes, applications need to share access to data or persist data after a container is deleted. Databases, user-generated content for a web site and log files are just a few examples of data that is impractical or impossible to include in a Docker image but which applications need to access. Persistent access to data is provided with Docker Volumes.
check volume persistence
Create an independent volume and Inspect it.
docker volume create --name DV_apple #it allows you to create a volume without relating to any particular containers.

Create a container and attach it with the volume ---> Write sth to the voulme--->Exit. Note that If /dv_apple exest, the content in it will be hidden. --rm means remove the container when exiting the container.

Where it the greetings.txt? It's here

Create a new container and attach it with the same volume--->Read the same content from the volume--->Exit

VICTORY! Volume persistence is verified.
Note:
(1)-v /path:/path/in/container VS -v path:/path/in/container
the former loads a host dir while the latter loads a volume.
(2)volume can only be removed(use docker volume rm vol_name) if all containers referred to it are removed(not stopped).
(3)you can’t mount a host directory(-v /path:/path/in/container) from Dockerfile because built images should be portable while a host directory wouldn’t be available on all potential hosts.
what if /path/in/container has data?
The answer is the data will be copied into the volume. Lets see

After exiting, we start a new container that attach DV_orange

We see that DV_orange has a copy of the contents of the base image's /var dir. To further check, see

share data among multiple containers
So far, we've attached a volume to one container at a time. But often, we'll want multiple containers to attach to the same data volume. This is relatively straightforward to accomplish, but there's one critical caveat: at this time, Docker doesn't handle file locking. If you need multiple containers writing to the volume, the applications running in those containers must be designed to write to shared volume in order.
First, create container con1:

Then, create container con2:

Finally, restart con1 and check mix_msg.txt:

NOTE:
(1)The other way to avoid data corruption is to let all the other containers only have the read-only right for the shared volume.
(2)Any changes in /path will reflect in /path/in/container realtime, and any changes in /path/in/container will reflect in /path realtime.
Mount a shared-storage volume as a data volume
In addition to mounting a host directory in your container, some Docker volume plugins allow you to provision and mount shared storage, such as iSCSI, NFS, or FC. Here we use flocker plugin which is a volume plugin that provides multi-host portable volumes for Docker, enabling you to run databases and other stateful containers and move them around across a cluster of machines.
docker run -d -P --volume-driver=flocker -v my-named-volume:/webapp --name web training/webapp python app.py
#with flocker volume driver we create a shared volume named "my-named-volume" and mount it to /webapp
you may also use the docker volume create command, to create a volume before using it in a container:
Docker-3:Data Volume的更多相关文章
- docker 使用Data Volume 共享文件
Adding a data volume You can add a data volume to a container using the -v flag with the docker run ...
- Data Volume 之 bind mount - 每天5分钟玩转 Docker 容器技术(39)
storage driver 和 data volume 是容器存放数据的两种方式,上一节我们学习了 storage driver,本节开始讨论 Data Volume. Data Volume 本质 ...
- centos7下安装docker(13.1docker存储--data volume)
我们现在知道docker 有两种存储方式:storage driver和data volume stroage driver这种存储方式主要是存储那些无状态的数据,是镜像层和容器层组成的,而data ...
- Docker容器的数据卷(data volume),数据卷容器,数据卷的备份和还原。
Docker容器的数据卷(data volume),数据卷容器,数据卷的备份和还原. 数据卷就是数据(一个文件或者文件夹). Docker的理念之一是将应用与其运行的环境打包,docker容器的生命周 ...
- Docker 容器数据卷(Data Volume)与数据管理
卷(Volume)是容器中的一个数据挂载点,卷可以绕过联合文件系统,从而为Docker 提供持久数据,所提供的数据还可以在宿主机-容器或多个容器之间共享.通过卷,我们可以可以使修改数据直接生效,而不必 ...
- [转帖]Docker的数据管理(volume/bind mount/tmpfs)
Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs) https://www.cnblogs.com/zhuochong/p/10069719.html do ...
- 039、Data Volume 之 bind mount (2019-02-28 周四)
参考https://www.cnblogs.com/CloudMan6/p/7142150.html Date Volume 本质上是Dokcer host文件系统中的目录或者文件,能够直接被 ...
- Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs)
Docker提供了三种不同的方式用于将宿主的数据挂载到容器中:volumes,bind mounts,tmpfs volumes.当你不知道该选择哪种方式时,记住,volumes总是正确的选择. vo ...
- 第 6 章 存储 - 039 - Data Volume 之 bind mount
Data Volume Data Volume 本质上是 Docker Host 文件系统中的目录或文件,能够直接被 mount 到容器的文件系统中. Data Volume 有以下特点: 1.Dat ...
随机推荐
- JQuery 插件之Ajax Autocomplete(ajax自动完成)搜索引擎自动显示下拉框
平时用百度,谷歌搜索的时候 会有一个下 拉列表进行提示 这是一个非常好的功能 本文要介绍的这个JQuery 插件 名叫Ajax Autocomplete 顾名思义 ajax 也就是用ajax的方式获取 ...
- ExtJs6.0.0随笔
环境:extJs6.0.0GPL,对应SenchaCmd-6.0.2-windows-64bit(注意版本不能太高). 步骤: 1.安装senchaCmd 2.运行生成demo: http://doc ...
- 解决phalcon读取mysql乱码
原先的项目用的是phalcon,迁移到新服务器上面后中文字符变为'?',即便连接参数设置了charset => 'utf8'也无效,一开始怀疑是版本问题,后来直接拷过去完全一样的库也没用:最后还 ...
- 机器学习--Classifier comparison
最近在学习机器学习,学习和积累和一些关于机器学习的算法,今天介绍一种机器学习里面各种分类算法的比较 #!/usr/bin/python # -*- coding: utf-8 -*- "&q ...
- DIOCP之DEMO-Echo卡死问题分析
最近很多新朋友在调试echo这个例程时发现,总是卡死客户端或服务器端,这是因为客户端的接收数据用的memo没有处理接受到的行数,导致超过最大行数,而卡死界面,只需要如下操作就可以解决: 引用弦子的:虽 ...
- 循序渐进Python3(十)-- 4 -- paramiko
paramiko模块,基于SSH用于连接远程服务器并执行相关操作. 使用 (1)SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: , ))transport.connect( ...
- ORACLE 获取程序当前位置的方法
FUNCTION f_Get_Program_Position RETURN VARCHAR2 IS l_Owner ); l_Name ); l_Lineno NUMBER; l_Type ); B ...
- Types of Learning
从四个角度大致总结一下不同类型的机器学习问题. 1. 按照输出空间的变化: 分类问题(二分类.多分类).回归问题 2. 按照输出的标记变化: 监督学习 与 非监督学习 与 半监督学习(树的识别) 与 ...
- 浅谈WebSocket
WebSocket是H5提出的为了解决客户端和服务器双工通信的方法.在我们使用HTTP协议通信时,客户端主动向服务器发送请求,得到服务器端数据.为了与服务器端数据保持一致,之前常用的有轮询和长轮询两种 ...
- Oracle 更新表(另一张表)
Update a set(a.province,a.city)= (select province,city from b where b.mobile=a.mobile)