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 —— 服务器端发送JSON数据
重点需要解决的问题:服务器端如何构建JSON数据 思考:JavaBean转JSON数据,集合转JSON数据,普通java对象(String,Number)转JSON数据 一.Gson开源jar包 ...
- ELKStack之极速入门(上)
ELKStack之极速入门(上) 链接:https://pan.baidu.com/s/1V2aYpB86ZzxL21Hf-AF1rA 提取码:7izv 复制这段内容后打开百度网盘手机App,操作更方 ...
- Linux系统基于fork()新进程的创建
作者:严哲璟 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 fork属于系 ...
- HTML基础用 表格做报表
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- RPC_简洁版
1.定义服务接口 public interface RpcService { int printHello(int msg); } 2.定义服务接口实现类 public class RpcInterf ...
- Code Festival 2017 Qual B E Popping Balls
传送门 神仙计数! 我的计数真的好差啊= = 不过这个题真的神仙 看了题解把整个过程在草稿纸上重写了一遍才想明白= =(一张草稿纸就没有了!!!) 计数的关键就是在于 枚举的有效性和独立性[不能重复计 ...
- PL/SQL-FOR UPDATE 与 FOR UPDATE OF的区别
PL/SQL-FOR UPDATE 与 FOR UPDATE OF的区别 数据库 oracle for update of 和 for update区别 select * from T ...
- leetcode-15双周赛-1287-有序数组中出现次数超过25%的元素
题目描述: 方法一:二分法 class Solution: def findSpecialInteger(self, arr: List[int]) -> int: span = len(arr ...
- npm和gem
https://blog.csdn.net/u011099640/article/details/53083845
- JS知识—面试准备(一)
1.JS内置类型 分为基本数据类型和Object.基本数据类型有:null,undefined,string,boolean,number,symbol. console.log(typeof nul ...