4533 发表于 2015-12-24 09:31:05

docker创建数据卷以及数据卷容器

docker容器管理有2中方式:1:数据卷:类似Linux下目录挂载mount2:数据卷容器:其实就是一个正常的容器,专门用来提供数据卷供其它容器挂载的
使用docker search xxx //xxx指的是搜索相应的镜像。搜索后根据自己需求进行pull
下载镜像root@zxl-node4:~# docker pull jdeathe/centos-ssh查看pull后的镜像root@zxl-node4:~# docker imagesREPOSITORY         TAG               IMAGE ID            CREATED             VIRTUAL SIZEjdeathe/centos-ssh   latest            ebb3f7483e15      4 weeks ago         276.2 MB数据卷运行容器名字为node1,并在容器内挂载/data-node1数据卷
1
2
:~# docker run -itd --name node1 -v /data-node1 jdeathe/centos-ssh /bin/bash
a51fbc7cf66c4db39316e96b777f3a53900c25bcae8cb227491742b7f3fe6656




进入node1容器

1
:~# ./docker-enter node1




查看容器内挂载的数据卷

1
2
3
4
5
6
7
# ll /data-node1/

total 0

# ll /data-node1/-d

drwxr-xr-x 2 root root 4096 Dec 23 01:36 /data-node1/






挂载本地目录作为容器node2数据卷
查看本地目录文件
1
2
3
4
root@zxl-node4
:~# ls /data/

dockernginxweb1web2




运行容器node2,本地/data目录作为容器node2的数据卷

1
2
3
4
root@zxl-node4
:~# docker run -itd --name node2 -v /data:/data-node1 jdeathe/centos-ssh /bin/bash

0d935fcad74b00b86f0264c466853813426b3dc50ac6bd98377cfa608500b851




进入容器node2

1
:~# ./docker-enter node2




查看容器内的挂载本地目录对应数据卷目录文件信息

1
2
3
4
5
6
7
# ls /data-node1/

dockernginxweb1web2

# cat /data-node1/docker

This is a docker containers




容器挂载其他容器的数据卷
# logout
运行容器node3,挂载数据卷来自容器node1的数据卷

1
2
3
:~# docker run -itd --name node3 --volumes-from node1jdeathe/centos-ssh /bin/bash

5a4ef366033418a4f1c1b8de02d32960ee413f525eb0398fb831074892010d45




进入node3容器,并查看相关数据卷目录文件信息

1
2
3
4
5
6
7
8
9
10
11
:~# ./docker-enter node3

# ls /data-node1/

# ls /data-node1/ -d

/data-node1/

# ls -l /data-node1/ -d

drwxr-xr-x 2 root root 4096 Dec 23 01:36 /data-node1/




运行其他容器依然可以继续挂载其他容器的数据卷

1
2
3
4
5
6
7
8
9
10
11
# logout

:~# docker run -itd --name node4 --volumes-from node1jdeathe/centos-ssh /bin/bash

571c7712daecbf0c0bccf02b1b3e615d61b14aeba95360013dd35d5a277dfa03

:~# ./docker-enter node4

# ls -l /data-node1/ -d

drwxr-xr-x 2 root root 4096 Dec 23 01:36 /data-node1/




注:以上是关于容器创建数据卷相关信息

页: [1]
查看完整版本: docker创建数据卷以及数据卷容器