zoukankan      html  css  js  c++  java
  • Docker容器持久化存储——volume卷管理

     1. 宿主机与容器之间的文件拷贝

      docker container cp 拷贝谁 到哪里    --涉及到容器时要注意格式: name:路径; 如 ....cp 容器名:/data/file ./file

    1 启动挂载数据卷

    [root@docker httpd]# docker run -d -p 8083:80 --name "http8083" -v /opt/Volume/httpd:/usr/local/apache2/htdocs httpd
    733eefea35456e47e71775b502e0376aff24b55612fe3030c8690d22870e8f29
    [root@docker httpd]# docker run -d -p 8084:80 --name "http8084" -v /opt/Volume/httpd:/usr/local/apache2/htdocs httpd
    47d3059e9aa8af3322665815748c065ba6ad26d6f81fa60b61261873889deb40
    
    [root@docker httpd]# curl 10.0.0.110:8083
    test volume
    [root@docker httpd]# curl 10.0.0.110:8084
    test volume

    # 启动容器时使用-v参数来指定宿主机和容器目录的对应关系; -v 宿主机目录:容器目录
    # 挂载后修改宿主机对应目录中内容会时时映射到容器目录的.
    # 查看容器挂载卷的信息依然可以使用docker container inspect name来查看

    2 数据卷容器

    需求: 需要生成多个容器, 挂载宿主机的同一个目录到容器中的相同路径下, 可以挨个在生成时使用-v指定, 那如果有成千上万个容器需求呢? 此时我们就需要使用数据卷容器来解决了.

    # 先生成数据卷容器
    docker run -it --name "httpd_volumes" -v /opt/Volume/httpd_volume/conf:/usr/local/apache2/conf -v /opt/Volume/httpd_volume/html:/usr/local/apache2/htdocs centos:6.9 /bin/bash ctrl p q  # 因为上面使用的是-it命令, 交互式生成的容器. 在容器中使用ctrl + p +q 可把该容器丢到后台运行, 而不至于在退出时容器被销毁.

    # 使用数据卷容器 docker run -d -p 8085:80 --volumes-from httpd_volumes --name "http8085" httpd docker run -d -p 8086:80 --volumes-from httpd_volumes --name "http8086" httpd
    补充: 使用--volumes-from参数来指定数据卷容器

    66

  • 相关阅读:
    sublime开启vim模式
    git命令行界面
    搬进Github
    【POJ 2886】Who Gets the Most Candies?
    【UVA 1451】Average
    【CodeForces 625A】Guest From the Past
    【ZOJ 3480】Duck Typing
    【POJ 3320】Jessica's Reading Problemc(尺取法)
    【HDU 1445】Ride to School
    【HDU 5578】Friendship of Frog
  • 原文地址:https://www.cnblogs.com/quzq/p/13429469.html
Copyright © 2011-2022 走看看