docker 容器_数据卷数据卷容器使用
一、创建docker容器
(1)docker容器常见的选项
-i:保持容器打开的状态
-t:分配一个伪终端
-d:后台运行
--name:指定容器的名字
(2)创建容器,容器的名字是centos01
[root@centos01 ~]# docker create -it --name centos01 hub.c.163.com/public/centos:6.7-tools
(3)查看运行的容器
[root@centos01 ~]# docker ps
(4)查看所有的容器
[root@centos01 ~]# docker ps -a
(5)启动容器
[root@centos01 ~]# docker start centos01
(6)停止运行的容器
[root@centos01 ~]# docker stop centos01
(7)删除停止的容器
[root@centos01 ~]# docker rm centos01
(8)删除启动的容器
二、创建并启动docker容器
(1)创建并启动docker容器输出hello world
[root@centos01 ~]# docker run --name centos02 hub.c.163.com/public/centos:6.7-tools /bin/echo "hello world"
(2)创建并运行容器,容器的名字是centos03
[root@centos01 ~]# docker run -it --name centos03 hub.c.163.com/public/centos:6.7-tools /bin/bash
(3)创建一个保持打开的容器
[root@centos01 ~]# docker run -d --name centos04 hub.c.163.com/public/centos:6.7-tools /bin/sh -c "while true;do echo hello world;sleep 1;done"
(4)查看docker容器的日志
[root@centos01 ~]# docker logs centos04
(5)登录后台运行的容器
[root@centos01 ~]# docker exec -it centos04 /bin/bash
三、容器的导入和导出备份
(1)将容器导出备份
[root@centos01 ~]# docker export centos04 > ./centos04.tar
(2)将导出的容器导入到docker镜像中
[root@centos01 ~]# cat ./centos04.tar | docker import - centos6.7:v1.0
(3)使用新的docke镜像,生成一个容器
[root@centos01 ~]# docker run -it -d --name centos05 centos6.7:v1.0 /bin/bash
(4)删除所有的容器
[root@centos01 ~]# docker rm -f $( docker ps -a -q )
四、docker数据管理和端口映射
1、docker数据卷的使用
(1)创建容器挂载数据卷/data1
[root@centos01 ~]# docker run -it -d --name centos01 -v /data1 centos6.7:v1.0 /bin/bash
(2)实现宿主机数据共享到容器中(redis.iso)
登录到centos01容器中进行查看:
(3)默认数据卷保存的位置
/var/lib/docker/volumes/
2、docker数据卷容器
(1)docker数据容器的作用
需要管理员创建数据卷容器
将数据容器共享到其他容器使用
实现容器和容器之间数据共享
(1)创建数据卷容器
[root@centos01 ~]# docker run -it -d --name database -v /data1 centos6.7:v1.0 /bin/bash
(2)创建容器连接到数据卷容器上
[root@centos01 ~]# docker run -it --volumes-from database --name centos01 centos6.7:v1.0 /bin/bash
[root@centos01 ~]# docker run -it --volumes-from database --name centos02 centos6.7:v1.0 /bin/bash

浙公网安备 33010602011771号