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 将宿主机上的任 ...
随机推荐
- Algorithms4th 1.1.25 欧几里得算法——数学归纳法证明
欧几里得算法的自然语言描述 计算两个非负整数p和q的最大公约数: 若q是0,则最大公约数为p.否则将p除以q得到余数r,p和q的最大公约数即为q和r的最大公约数. 数学归纳法证明 基础步骤: 若q = ...
- 环境管理 pipenv 的 使用
安装 pip3 install pipenv 配置 配置 环境变量 WORKON_HOME , 表示 生成的虚拟环境 文件 的 存放位置 创建虚拟环境 方式一 pipenv --python 3.7 ...
- Sass函数:数字函数-round()函数
round() 函数可以将一个数四舍五入为一个最接近的整数: >> round(12.3) 12 >> round(12.5) 13 >> round(1.4999 ...
- 【串线篇】spring boot配置文件大全【上】
一.配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的: • application.properties • application.yml 配置文件的作用:修改SpringB ...
- Python3.5-20190529-os模块
os.getcwd() 获取当前路径os.listdir("路径") 返回该路径下面所有的文件os.path.abspath(path):返回path的绝对路径.os.path.s ...
- mysql中的key primary key 和unique key
mysql 中key就等同于index 所以 key:普通索引 unique key:唯一索引,就是这一列不能重复 primary key:主键索引,就是不能为空,且主键索引不是完全相同时,插入新数据 ...
- tensorflow的boolean_mask函数
在mask中定义true,保留与其进行运算的tensor里的部分内容,相当于投影的功能. mask与tensor的维度可以不相同的,但是对应的长度一定要相同,也就是要有一一对应的部分: 结果的维度 = ...
- tuple unpacking
拆开Tuple lax_coordinates = (33.9425, -118.408056) latitude, longitude = lax_coordinates # tuple unpac ...
- 明明不太合适但是还是被用在配置文件和数据传输上的XML
XML概述: 概念: 可扩展的标记语言. 功能: 作为数据本地存储的格式.(已淘汰)作为结构化存储的方式,不如数据库效率高.目前一部分移动设备中还在使用. 作为网络中传输数据的格式.(已淘汰)作为网络 ...
- vue 项目的运行与 打包
1.vue init webpack 2.npm install axios 3.npm run dev 运行项目 4.npm run build 打包项目 会生成一个dist 文件夹,我们只需要把 ...