zoukankan      html  css  js  c++  java
  • 40-用 volume container 共享数据

    volume container 是专门为其他容器提供 volume 的容器。它提供的卷可以是 bind mount,也可以是 docker managed volume。下面我们创建一个 volume container:

    我们将容器命名为 vc_data(vc 是 volume container 的缩写)。注意这里执行的是 docker create 命令,这是因为 volume container 的作用只是提供数据,它本身不需要处于运行状态。容器 mount 了两个 volume:

    1. bind mount,存放 web server 的静态文件。

    2. docker managed volume,存放一些实用工具(当然现在是空的,这里只是做个示例)。

    通过 docker inspect 可以查看到这两个 volume。

    其他容器可以通过 --volumes-from 使用 vc_data 这个 volume container:

    三个 httpd 容器都使用了 vc_data,看看它们现在都有哪些 volume,以 web1 为例:

    web1 容器使用的就是 vc_data 的 volume,而且连 mount point 都是一样的。验证一下数据共享的效果

    下面我们讨论一下 volume container 的特点:

    1. 与 bind mount 相比,不必为每一个容器指定 host path,所有 path 都在 volume container 中定义好了,容器只需与 volume container 关联,实现了容器与 host 的解耦

    2. 使用 volume container 的容器其 mount point 是一致的,有利于配置的规范和标准化,但也带来一定的局限,使用时需要综合考虑。

    另一种在容器之间共享数据的方式是 data-packed volume container,下一节讨论。

  • 相关阅读:
    10.flask博客项目实战五之用户登录功能
    09.flask博客项目实战四之数据库
    08.flask博客项目实战三之表单
    07.flask博客项目实战二之模板使用
    06.flask博客项目实战一之项目框架搭建
    05.flask数据库
    04.flask表单
    03.flask模板
    idea 灵异事件之maven 缓存
    如何查看Spring Boot 默认的数据库连接池类型
  • 原文地址:https://www.cnblogs.com/mkxfs/p/10960812.html
Copyright © 2011-2022 走看看