docker--数据持久化之Data Volume
使用mysql为例
查看docker hub官方的mysql image 的dockerfile,有这一行:VOLUME /var/lib/mysql
-v给volume创建别名
[root@localhost ~]# docker run -d --name mysql1 -v mysql:/var/lib/mysql --name mysql1 -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:5.7.
31584edba6eb9b4aa772076f1c2d73c5eb7b4f1e62dd24b41c68518bdf62e11a
[root@localhost ~]#
[root@localhost ~]# docker volume ls
DRIVER VOLUME NAME
local mysql
[root@localhost ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
31584edba6eb mysql:5.7. "docker-entrypoint.s…" seconds ago Up seconds /tcp, /tcp mysql1
[root@localhost ~]# docker volume
create inspect ls prune rm
[root@localhost ~]# docker volume inspect mysql
[
{
"CreatedAt": "2019-07-22T03:09:06-07:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/mysql/_data",#在宿主机的挂账路径
"Name": "mysql",
"Options": null,
"Scope": "local"
}
]
[root@localhost ~]#
删了container,不删volume ,重新创建mysql container,数据还在
[root@localhost ~]# docker exec -it mysql1 /bin/bash
root@31584edba6eb:/# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) mysql> create database docker;
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| docker |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) mysql> exit
Bye
root@31584edba6eb:/# docker rm -f mysql1
bash: docker: command not found
root@31584edba6eb:/# exit
exit
[root@localhost ~]# docker rm -f mysql1
INFO[--22T03::25.954289600-:] ignoring event module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
WARN[--22T03::26.032476919-:] 31584edba6eb9b4aa772076f1c2d73c5eb7b4f1e62dd24b41c68518bdf62e11a cleanup: failed to unmount IPC: umount /var/lib/docker/containers/31584edba6eb9b4aa772076f1c2d73c5eb7b4f1e62dd24b41c68518bdf62e11a/mounts/shm, flags: 0x2: no such file or directory
mysql1
[root@localhost ~]# docker volume ls
DRIVER VOLUME NAME
local mysql
[root@localhost ~]# docker run -d --name mysql1 -v mysql:/var/lib/mysql --name mysql2 -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:5.7.
877377cb64ec6242d2cd9e821d3978e7f5e6d2dce791d88e605e3f5b2a098762
[root@localhost ~]# docker exec -it mysql2 /bin/bash
root@877377cb64ec:/# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| docker |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) mysql>
docker--数据持久化之Data Volume的更多相关文章
- 数据持久化之Data Volume
废话不多说直接操作 1.启动一个MySQL测试容器 [root@localhost labs]# docker pull mysql #下载MySQL镜像 [root@localhost labs]# ...
- Docker容器的数据卷(data volume),数据卷容器,数据卷的备份和还原。
Docker容器的数据卷(data volume),数据卷容器,数据卷的备份和还原. 数据卷就是数据(一个文件或者文件夹). Docker的理念之一是将应用与其运行的环境打包,docker容器的生命周 ...
- Docker数据持久化与容器迁移
上节讲到当容器运行期间产生的数据是不会在写镜像里面的,重新用此镜像启动新的容器就会初始化镜像,会加一个全新的读写入层来保存数据.如果想做到数据持久化,Docker提供数据卷(Data volume)或 ...
- Docker数据持久化及实战(Nginx+Spring Boot项目+MySQL)
Docker数据持久化: Volume: (1)创建mysql数据库的container docker run -d --name mysql01 -e MYSQL_ROOT_PASSWORD= my ...
- 22. docker 数据持久化 Data Volume
1 . 使用场景 在docker 容器被删除的时候 希望数据不丢失 2 . Volume 的使用 * 注意 在 mysql 的 Dockerfile 内 定义了 VOLUME ["var/ ...
- docker数据持久化/共享---volume,bind-mount,tmpfs-mount
一.将Docker数据挂载到容器 在Docker中,要想实现数据的持久化(所谓Docker的数据持久化即数据不随着Container的结束而结束),需要将数据从宿主机挂载到容器中.目前Docker提供 ...
- docker数据持久化
转载/参考: https://www.jianshu.com/p/ef0f24fd0674 Docker的数据持久化主要有两种方式: bind mount docker managed volume ...
- Docker | 数据持久化与数据共享
数据持久化(安装MySQL) 参考另一篇Docker安装mysql: https://www.cnblogs.com/all-smile/p/16778376.html MySQL的数据持久化问题 # ...
- 23. docker 数据持久化 bind mounting
1. bind mounting 和 data volume 的区别 data volume 需要在 Dockerfile 定义 Volume bind mounting 只需要 -v 指明 容器外部 ...
- `docker数据持久化volume和bind mounts两种方式
将数据从宿主机到容器的三种方式: ,volumes:docker管理宿主机文件系统的一部分(/var/lib/docker/volumes)保存数据的最佳方式 ,bind mounts 将宿主机上的任 ...
随机推荐
- Ajax爬取豆瓣电影目录(Python)
下面的分析相当于一个框架,搞懂之后,对于类似的文字爬取,我们也可以实现.就算不能使用Ajax方法,我们也能够使用相同思想去爬取我们想要的数据. 豆瓣电影排行榜分析 网址:https://movie.d ...
- YARN的伪分布式安装
前提:安装完HDFS以后 1.修改mapred-site.xml 这个文件初始时是没有的,有的是模板文件,mapred-site.xml.template 所以需要拷贝一份,并重命名为mapred-s ...
- elasticsearch 基础 —— Update API
Update API 更新API允许基于提供的脚本更新文档.该操作从索引获取文档(与分片并置),运行脚本(使用可选的脚本语言和参数),并对结果进行索引(也允许删除或忽略操作).它使用版本控制来确保在& ...
- 390-基于Zynq UltraScale+ MPSoC的单板嵌入式计算机
基于Zynq UltraScale+ MPSoC的单板嵌入式计算机 概述:Aldec TySOM-3-ZU7EV,将Xilinx Zynq UltraScale+ ZU7EV MPSoC以及DDR4 ...
- 基于TI 多核DSP 的大数据智能计算处理解决方案
北京太速科技有限公司 大数据智能计算,是未来的一个发展趋势,大数据计算系统主要完成数据的存储和管理:数据的检索与智能计算. 特别是在智能城市领域,由于人口聚集给城市带来了交通.医疗.建筑等各方面的压力 ...
- CentOS下安装gdb的方法
https://blog.csdn.net/zlk252620068/article/details/79564944
- [BZOJ4278] [ONTAK2015]Tasowanie 贪心+后缀数组
题目链接 最近做题目好像有点东一榔头西一棒.好吧其实订正模拟题的时候需要用到什么感觉不太熟的就写一下吧. 显然直接贪心,比较两个点后面的串的字典序,小就选谁就可以了. 可以把两个串接起来,加一个\(i ...
- CentOS7.5 开启Samba服务
安装 yum install samba 其依赖关系包samba-client samba-common会自动安装上去 查看状态 service smb status 重启服务systemctl re ...
- Ubuntu查看和自动挂载硬盘
sudo blkid 查看UUID vim /etc/fstab 进行修改 如果 fstab 文件中的命令挂载的硬盘不存在,启动的时候会报错.
- CentOS6.8 安装/升级Python2.7.x,并安装最新setuptools、pip、fabric程序总结
最终靠谱的可借鉴文档: 1.python官网 2.http://lovesoo.org/python-fabric-yuan-cheng-zi-dong-bu-shu-jian-jie.html 3. ...