crpi-yy9yj7syn08stogn.cn-shanghai.personal.cr.aliyuncs.com/zhenh/zyan 1.1 ca7abefb7af7 40 hours ago 191MB
172.21.47.251:5000/zyan/hgubuntu 1.2 59ab366372d5 2 weeks ago 78.1MB
ubuntu latest 59ab366372d5 2 weeks ago 78.1MB
mysql 5.7 5107333e08a8 10 months ago 501MB
registry latest 75ef5b734af4 13 months ago 25.4MB
redis 6.0.8 16ecd2772934 4 years ago 104MB
复制代码
3.利用mysql:5.7镜像创建容器(也叫运行镜像)
简单版 – 有坑版
1. 查看端口 并启动mysql5.7
# 查看端口3306 是否占用
[root@localhost ~]# ps -ef | grep mysql
root 4468 2013 0 12:30 pts/0 00:00:00 grep --color=auto mysql
# 执行 ps -ef | grep mysql 后,只显示了一个进程信息,这个进程实际上是你自己运行的 grep 命令本身。这意味着在执行该命令时,并没有找到其他与 mysql 相关的正在运行的进程。
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
复制代码
成功启动
2. 进入mysql 建库建表插入数据
语句背面一定要加 ;
mysql> show database; # 错误语句
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1,'fff')' at line 1
mysql> insert into t1 values(1,'fff');
Query OK, 1 row affected (0.01 sec)
mysql> select * from t1;
+------+------+
| id | name |
+------+------+
| 1 | fff |
+------+------+
1 row in set (0.00 sec)
mysql>
复制代码
4.再新建库新建表再插入中文测试
mysql> select * from t1;
+------+--------+
| id | name |
+------+--------+
| 1 | fff |
| 3 | 昊哥 |
+------+--------+
2 rows in set (0.00 sec)
mysql>
复制代码
结论
5.测试删除容器 从新加载数据是否从新体现
[root@localhost mysql]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2390dee74aa9 mysql:5.7 "docker-entrypoint.s…" 15 minutes ago Up 10 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp fervent_mclean
[root@localhost mysql]# ls -l
总用量 4
drwxr-xr-x. 2 root root 20 10月 30 13:09 conf
drwxr-xr-x. 6 polkitd root 4096 10月 30 13:13 data
drwxr-xr-x. 2 root root 6 10月 30 13:05 log
[root@localhost mysql]# coker rm -f 2390dee74aa9
bash: coker: 未找到命令...
[root@localhost mysql]# docker rm -f 2390dee74aa9
2390dee74aa9
[root@localhost mysql]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost mysql]#
复制代码
这个实例再次验证了容器卷挂载的必要性 ,即使日常手误删除了相干的操作, 仍有机会举行数据复原
答疑解惑
关于命令挂载那一块
-v /zza/mysql/conf:/etc/mysql/conf.d
-v /zza/mysql/log:/var/log/log
-v /zza/mysql/data:/var/lib/mysql
复制代码
配置好的mysql上传到私有库举行生存
1. 查看私有库已存在的镜像
运行registry 镜像
查看镜像
查看私有库存在的镜像
[root@localhost conf]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
crpi-yy9yj7syn08stogn.cn-shanghai.personal.cr.aliyuncs.com/zhenh/zyan 1.1 ca7abefb7af7 41 hours ago 191MB
172.21.47.251:5000/zyan/hgubuntu 1.2 59ab366372d5 2 weeks ago 78.1MB