设为首页 收藏本站
查看: 1037|回复: 0

[经验分享] docker 关于管理数据

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-10-24 09:17:20 | 显示全部楼层 |阅读模式
storage   overview
  • The data won’t persist(持久) when that container is no longer running, and it can be difficult困难 to get the data out of the container容器里 if another process needs it.
  • A container’s writable layer is tightly紧密的 coupled耦合 to the host machine where the container is running. You can’t easily轻易的 move the data somewhere else.
  • Writing into a container’s writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel.  This extra abstraction(抽象) reduces performance as compared to using data volumes, which write directly to the host filesystem.与使用直接写到主机文件系统的数据量相比,这种额外的抽象降低了性能。



mount  data into a container(three way):
volumes, bind mounts, or tmpfs volumes.volumes are almost always the right choice.

Choose the right type of mount
No matter which type of mount you choose to use, the data looks the same from within the container. It is exposed as either(任何一个) a directory or an individual(个别的) file in the container’s filesystem.
An easy way to visualize(显现) the difference(差别) among volumes, bind mounts, and tmpfs mounts is to think about where the data lives on the Docker host(可以考虑数据在Docker主机上的位置
.

Volumes are stored in a part of the host filesystem which is managed by Docker (/var/lib/docker/volumes/ on Linux). Non-Docker processes非docker进程 should not modify this part of the filesystem. Volumes are the best way to persist持久 data in Docker.
Bind mounts may be stored anywhere任何地方 on the host system. They may even be important 重要system files or directories. Non-Docker processes on the Docker host or a Docker container can modify them at any time.
tmpfs mounts are stored in the host system’s memory only, and are never written to the host system’s filesystem.
More details about mount types
Volumes: Created and managed by Docker. You can create a volume explicitly(明确的) using the docker volume create command, or Docker can create a volume during container or service creation.
When you create a volume, it is stored within a directory on the Docker host. When you mount the volume into a container, this directory is what is mounted into the container. This is similar to the way that bind mounts work, except that volumes are managed by Docker and are isolated from the core functionality of the host machine(主机的核心功能跟李出来).bind  mount  是和我们平时挂载文件是一样的。出来这个是由docker管理的
A given volume can be mounted into multiple containers simultaneously(同时). When no running container is using a volume, the volume is still available(可用) to Docker and is not removed automatically. You can remove unused volumes using docker volume prune.
When you mount a volume, it may be named(命名) or anonymous(匿名). Anonymous volumes are not given an explicit(指定) name when they are first mounted into a container, so Docker gives them a random(随机的) name that is guaranteed(保证) to be unique(独一无二) within a given Docker host. Besides the name, named and anonymous volumes behave in the same ways. 匿名和命名卷都是一样的,只是出来名字之外。
Volumes also support the use of volume drivers, which allow you to store your data on remote hosts or cloud providers, among other possibilities.


Bind mounts: Available(使用) since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced(引用) by its full path(完整路径) on the host machine. The file or directory does not need to exist on the Docker host already. It is created on demand(需求) if it does not yet exist. Bind mounts are very performant(高性能), but they rely on the host machine’s filesystem having a specific directory structure(结构) available(可用). If you are developing开发 new Docker applications, consider using named volumes instead. You can’t use Docker CLI commands to directly(直接) manage bind mounts.

警告:使用绑定挂载的副作用之一是,您可以通过在容器中运行的进程更改主机文件系统,包括创建、修改或删除重要的系统文件或目录。这是一种强大的功能,可以对安全产生影响,包括对主机系统的非docker进程产生影响。



tmpfs mounts: A tmpfs mount is not persisted on disk, either on the Docker host or within a container(不是在docker主机或者一个容器). It can be used by a container during the lifetime(生命周期) of the container, to store non-persistent state or sensitive(敏感) information. For instance, internally(在内部), swarm services use tmpfs mounts to mount secrets into a service’s containers.


Bind mounts and volumes can both mounted into containers using the -v or --volume flag, but the syntax(语法) for each is slightly different(略有不同). For tmpfs mounts, you can use the --tmpfs flag. However, in Docker 17.06 and higher, we recommend using the --mount flag for both containers and services, for bind mounts, volumes, or tmpfs mounts, as the syntax is more clear.

Good use cases for volumes
Volumes are the preferred(优先的) way to persist data in Docker containers and services. Some use cases for volumes include:
Sharing data among multiple running containers. If you don’t explicitly create it, a volume is created the first time it is mounted into a container. When that container stops or is removed, the volume still exists.

When the Docker host is not guaranteed to have a given directory or file structure. Volumes help you decouple the configuration of the Docker host from the container runtime.(当Docker主机不保证拥有给定的目录或文件结构时。卷帮助您将Docker主机的配置与容器运行时分离。


When you want to store your container’s data on a remote host or a cloud provider, rather than locally.

When you need to be able to back up, restore, or migrate data from one Docker host to another, volumes are a better choice. You can stop containers using the volume, then back up the volume’s directory (such as /var/lib/docker/volumes/<volume-name>).

Good use cases for bind mounts
In general, you should use volumes where possible. Bind mounts are appropriate for the following types of use case:
Sharing configuration files from the host machine to containers. This is how Docker provides DNS resolution to containers by default, by mounting /etc/resolv.conf from the host machine into each container.


Good use cases for tmpfs mounts
tmpfs mounts are best used for cases when you do not want the data to persist either on the host machine or within the container. This may be for security reasons or to protect the performance of the container when your application needs to write a large volume of non-persistent state data.当你不想数据持久性。tmpfs挂载最好用于情况。当您的应用程序需要编写大量非持久状态数据时,这可能是出于安全考虑,也可能是为了保护容器的性能。

Tips for using bind mounts or volumes
如果您将一个空卷装入容器中,在这个容器中存在文件或目录,那么这些文件或目录将被传播(复制)到卷中。类似地,如果您启动一个容器并指定一个尚未存在的卷,则为您创建一个空卷。这是预填充另一个容器需要的数据的好方法。
    如果你挂载一个绑定挂载或非空卷成目录的容器一些文件或目录存在,这些文件或目录被挂载,就像如果你保存文件到/ mnt Linux主机上然后u盘挂载到/ mnt。在USB驱动器被卸载之前,/mnt的内容会被USB驱动器的内容所掩盖。模糊的文件没有被删除或修改,但是在绑定挂载或卷安装时不可访问。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-405799-1-1.html 上篇帖子: Docker虚拟化轻量容器技术 最新版视频教程 下篇帖子: docker数据存储方式(tmpfs)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表