一、线上考试系统的数据 虚拟化技术部署
1、部署前端服务器
(1)将资源上传到服务器
scp -r dist/ root@192.168.1.11:~
(2)创建基础容器 在服务器上
systemctl start docker.service
docker pull centos
docker run -it --name c1 centos:latest /bin/bash
(3)在容器中修改yum源
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo #阿里云镜像
yum clean all && yum makecache
(4)在容器中安装epel
yum -y install epel-release
(5)在容器中安装nginx
yum -y install nginx
(6)ctrl+p+q
(7)导出tar包
docker export -o centos_nginx.tar c1
(8)引入tar包,称为镜像
docker import -m "山不向我走来,我就向山走去" centos_nginx centos:nginx
(9)查看镜像
docker images ls
docker images
(10)停用c1容器,删除c1容器
docker stop c1
docker rm c1
(11)创建新的centos nginx容器,在创建的同时指定端口,以及挂载目录
docker run -it --name c1 -p80:80/tcp -v /opt/:/usr/share/nginx/html/ centos:nginx /bin/bash
nginx #在容器内部启动nginx
ctrl+p+q
cp -r dist/* /opt/
(12)浏览器访问192.168.1.11
2、docker创建mysql环境
(1)启动docker守护进程
systemctl start docker.service
(2)搜索mysql镜像
docker search mysql
(3)拉取mysql镜像
docker pull mysql
(4)创建镜像容器
[root@Docker ~]# docker run -it --name mysql0 mysql:latest /bin/bash
(5)管理mysql
[root@Docker ~]# docker exec -it m0 mysql -uroot -proot
具体操作
[root@Docker ~]# systemctl start docker
[root@Docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos nginx 28eae436e8fc 3 hours ago 366MB
centos latest 5d0da3dc9764 2 years ago 231MB
[root@Docker ~]# docker run -it --name mysql0 mysql:latest /bin/bash
Unable to find image 'mysql:latest' locally
latest: Pulling from library/mysql
6e839ac3722d: Pull complete
ad912193ad5f: Pull complete
25d13d87fd8d: Pull complete
004d383c75ef: Pull complete
6d9bbc82a0b8: Pull complete
81fec07ea550: Pull complete
83357cb2d3a5: Pull complete
8ffe968b82c1: Pull complete
30dfd9a7ed57: Pull complete
35844ae33cbe: Pull complete
Digest: sha256:86cdfe832c81e39a89cfb63c3fde1683c41cc00ef91e67653c9c1df0ba80f454
Status: Downloaded newer image for mysql:latest
bash-5.1#
bash-5.1# exit
exit
[root@Docker ~]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ce66ba050af6 mysql:latest "docker-entrypoint.s…" 39 seconds ago Exited (0) 8 seconds ago mysql0
4e6ec10ab435 centos:nginx "/bin/bash" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp, :::80->80/tcp c1
[root@Docker ~]# docker start mysql0
mysql0
[root@Docker ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
Digest: sha256:86cdfe832c81e39a89cfb63c3fde1683c41cc00ef91e67653c9c1df0ba80f454
Status: Image is up to date for mysql:latest
docker.io/library/mysql:latest
[root@Docker ~]# docker run -d --name m0 -e MYSQL_ROOT_PASSWORD=root -p3306:3306 mysql:latest
2d4f51a55f6e5e6e955550e7ddf71f390d53313d15e785f96ecd2bae3fd902d4
[root@Docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d4f51a55f6e mysql:latest "docker-entrypoint.s…" 18 seconds ago Up 17 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp m0
ce66ba050af6 mysql:latest "docker-entrypoint.s…" 4 minutes ago Up 3 minutes 3306/tcp, 33060/tcp mysql0
4e6ec10ab435 centos:nginx "/bin/bash" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp, :::80->80/tcp c1
[root@Docker ~]# docker exec -it m0 mysql -uroot -proot
mysql>
打开Navicat连接虚拟机mysql,然后上传sql文件,在进入虚拟机查看
mysql> show databases;
+---------------------+
| Database |
+---------------------+
| information_schema |
| mysql |
| performance_schema |
| project_exam_system |
| sys |
+---------------------+
5 rows in set (0.00 sec)
mysql> use project_exam_system;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-------------------------------+
| Tables_in_project_exam_system |
+-------------------------------+
| admin |
| category |
| com_city |
| com_nation |
| course |
| dept |
| dept_student |
| exam |
| exam_dept |
| exam_process |
| loginlog |
| major |
| menu |
| paper |
| paper_topic |
| role |
| role_admin |
| role_menu |
| semester |
| student |
| teacher |
| topic |
| user |
+-------------------------------+
23 rows in set (0.00 sec)
mysql> select * from user;
+-----+--------------+----------+--------+---------------------+----------+---------------------+--------+-------+
| id | userName | password | status | createTime | createOr | editTime | editOr | isDel |
+-----+--------------+----------+--------+---------------------+----------+---------------------+--------+-------+
| 1 | 21001189 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-22 22:04:44 | NULL | 0 |
| 2 | 21001190 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 3 | 21001191 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 4 | 21001192 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 5 | 21001193 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 6 | 21001194 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 7 | 21001195 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 8 | 21001196 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 9 | 21001197 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 10 | 21001198 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 11 | 21001199 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 12 | 21001200 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 13 | 21001201 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 14 | 21001202 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 15 | 21001203 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 16 | 21001204 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 17 | 21001205 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 18 | 21001206 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 19 | 21001207 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 20 | 21001208 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 21 | 21001209 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 22 | 21001210 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 23 | 21001211 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 24 | 21001212 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 25 | 21001213 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 26 | 21001772 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 27 | 21001793 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 28 | 21001807 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 29 | 21001910 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 30 | 21001912 | 111111 | 0 | 2024-08-21 09:45:05 | NULL | 2024-08-21 09:45:05 | NULL | 0 |
| 31 | 2021591101 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 32 | 2021591102 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 33 | 2021591103 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 34 | 2021591104 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 35 | 2021591105 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 36 | 2021591106 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 37 | 2021591107 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 38 | 2021591108 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 39 | 2021591110 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 40 | 2021591111 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 41 | 2021591112 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 42 | 2021591113 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 43 | 2021591114 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 44 | 2021591115 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 45 | 2021591116 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 46 | 2021591117 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 47 | 2021591118 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 48 | 2021591120 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 49 | 2021591121 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 50 | 2021591122 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 51 | 2021591123 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 52 | 2021591124 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 53 | 2021591125 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 54 | 2021591126 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 55 | 2021591127 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 56 | 2021591128 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 57 | 2021591129 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 58 | 2021591130 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 59 | 2021591131 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 60 | 2021591132 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 61 | 2021591133 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 62 | 2021591134 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 63 | 2021591136 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 64 | 2021591137 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 65 | 2021591138 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 66 | 2021591139 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 67 | 2021591140 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 68 | 2021591142 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 69 | 2021591143 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 70 | 2021591144 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 71 | 2021591145 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 72 | 2021591148 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 73 | 2021591149 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 74 | 2021591150 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 75 | 2021591153 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 76 | 2021591154 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 77 | 2021591155 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 78 | 202110060145 | 111111 | 0 | 2024-08-21 22:29:43 | NULL | 2024-08-21 22:29:43 | NULL | 0 |
| 79 | 2021591201 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 80 | 2021591202 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 81 | 2021591203 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 82 | 2021591205 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 83 | 2021591208 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 84 | 2021591209 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 85 | 2021591210 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 86 | 2021591212 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 87 | 2021591213 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 88 | 2021591214 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 89 | 2021591215 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 90 | 2016591111 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 91 | 2021591217 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 92 | 2021591218 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 93 | 2021591219 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 94 | 2021591220 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 95 | 2021591221 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 96 | 2021591222 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 97 | 2021591223 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 98 | 2021591224 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 99 | 2021591225 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 100 | 2021591226 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 101 | 2021591227 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 102 | 2021591228 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 103 | 2021591229 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 104 | 2021591230 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 105 | 2021591231 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 106 | 2021591232 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 107 | 2021591233 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 108 | 2021591234 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 109 | 2021591235 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 110 | 2021591236 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 111 | 2021591237 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 112 | 2021591238 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 113 | 2021591239 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 114 | 2021591240 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 115 | 2021591241 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 116 | 2021591242 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 117 | 2021591243 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 118 | 2021591244 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 119 | 2021591245 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 120 | 2021591246 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 121 | 2021591247 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 122 | 2021591248 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 123 | 2021591249 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 124 | 2021591250 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 125 | 2021591253 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 126 | 2021591255 | 111111 | 0 | 2024-08-21 22:31:54 | NULL | 2024-08-21 22:31:54 | NULL | 0 |
| 127 | 20217210013 | 111111 | 0 | 2024-08-21 22:33:19 | NULL | 2024-08-21 22:33:19 | NULL | 0 |
+-----+--------------+----------+--------+---------------------+----------+---------------------+--------+-------+
127 rows in set (0.00 sec)
mysql>
3、让容器和宿主机时间一致
让容器共享宿主机的/etc/localtime
[root@Docker ~]# docker run -it --name c0 centos:latest /bin/bash
[root@bff6b2bb3d9e /]# date
Mon Aug 26 06:37:27 UTC 2024
[root@Docker ~]# docker run -it --name c2 -v /etc/localtime:/etc/localtime centos:latest /bin/bash
[root@a33dae672ed9 /]# date
Mon Aug 26 14:39:45 CST 2024
扩展:exec命令
[root@Docker ~]# docker exec c2 ls /
[root@Docker ~]# docker exec c2 yum -y install nginx
扩展:容器的ip地址不稳定——link(容器的依赖)
--link 容器名:别名
(1)docker容器的ip地址是不固定,如果要作为服务器使用,就必须能够直接访问服务,不能直接使用ip,为容器设置域名,做端口映射也能保证,确定是一旦停用之后端口被占用,就无法再次启动了
(2)docker run --link 容器的名称或者是id:自定义域名
(3)被link容器必须处于启动状态,否则当前容器无法启动
[root@Docker ~]# docker run -it --name c0 --link m0:mysqldb centos:latest /bin/bash
[root@9a6bfee543cd /]# ping mysqldb
PING mysqldb (172.17.0.2) 56(84) bytes of data.
64 bytes from mysqldb (172.17.0.2): icmp_seq=1 ttl=64 time=0.079 ms
64 bytes from mysqldb (172.17.0.2): icmp_seq=2 ttl=64 time=0.052 ms
64 bytes from mysqldb (172.17.0.2): icmp_seq=3 ttl=64 time=0.051 ms
^C
--- mysqldb ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.051/0.060/0.079/0.015 ms
[root@9a6bfee543cd /]# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 mysqldb 5dd7947bfcaf m0
172.17.0.3 9a6bfee543cd
[root@Docker ~]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a6bfee543cd centos:latest "/bin/bash" 2 minutes ago Up 2 minutes c0
5dd7947bfcaf mysql:latest "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp m0
[root@Docker ~]# docker stop m0
m0
[root@Docker ~]# docker run -it --name c1 centos:latest /bin/bash
[root@Docker ~]# docker inspect c1
"IPAddress": "172.17.0.2",
[root@Docker ~]# docker start m0
m0
[root@Docker ~]# docker inspect m0
"IPAddress": "172.17.0.4",
[root@Docker ~]# docker attach c0
[root@9a6bfee543cd /]# ping mysqldb
PING mysqldb (172.17.0.4) 56(84) bytes of data.
64 bytes from mysqldb (172.17.0.4): icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from mysqldb (172.17.0.4): icmp_seq=2 ttl=64 time=0.085 ms
^C
--- mysqldb ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.085/0.089/0.094/0.010 ms
[root@9a6bfee543cd /]# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.4 mysqldb 5dd7947bfcaf m0
172.17.0.3 9a6bfee543cd
[root@9a6bfee543cd /]# exit
exit
[root@Docker ~]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aee1cf0eab53 centos:latest "/bin/bash" 5 minutes ago Up 5 minutes c1
9a6bfee543cd centos:latest "/bin/bash" 9 minutes ago Exited (127) 11 seconds ago c0
5dd7947bfcaf mysql:latest "docker-entrypoint.s…" 11 minutes ago Up 4 minutes 3306/tcp, 33060/tcp m0
[root@Docker ~]# docker stop c0 c1 m0
二、docker镜像容器
1.docker client向dcoker daemon 发送创建容器的请求
2.docker daemon查找有无客户端需要的镜像
3.如果没有,就到容器的镜像仓库下载需要的镜像
4.拿到容器镜像后,启动容器
分层
Docker 镜像就是一组只读的目录,或者叫只读的 Docker 容器模板,镜像中含有--件系统,所以我们说Docker 镜像是启动一个Docker 容器的基础。
可以将Docker 镜像看成是Docker 容器的静志时,也可将Docker 容器看成是Docker镜像的运行时。
从Docker 的官方文档来看,Docker 容器的定义和 Docker 镜像的定义几乎是相同,Docker 容器和Docker 镜像的区别主要在于docker 容器多出了一个可写层。
容器中的进程就运行在这个可写层,这个可写层有两个状态,即运行态和退出态。当我们docker run 运行容器后,docker 容器就进入了运行态,当我们停止正在运行中的容器时,docker 容器就进入了退出态
我们将容器从运行态转为退出态时,期间发生的变更都会写入到容器的文件系统中(需要注意的是,此处不是写入到了docker镜像中)。
联合文件系统(UnlonFS)是一种轻量级的高性能分层文件系统,它支持将文件系统中的修改信息作为一次提交并层层叠加,同时可以将不同出录挂载到同一个虚拟文件系统下,应用看到的是挂载的最终结果。
联合文件系统是实现Docker镜像的技术基础。Docker镜像可以通过分层来进行继承,例如,用户基于基础镜像(用来生成其他镜像的基础,往往没有父镜像)来制作各种不同的应用镜像。这些像共享同一个基础镜像层,提高了存储效率。此外,当用户改变了一个Docker镜像(比如升级程序到新的版本),则会创建一个新的层(layer)。因此,用户不用替换整个原镜像或者重新建立,只需要添加新层即可。用户分发镜像的时候,也只需要分发被改动的新层内容(增量部分)。这让Docker的镜像管理变得十分轻量级和快速。
操作
[root@Docker ~]# systemctl stop docker
[root@Docker ~]# cd /var/lib/docker/
[root@Docker docker]# ls
buildkit engine-id network plugins swarm volumes
containers image overlay2 runtimes tmp
[root@Docker docker]# cd overlay2/
[root@Docker overlay2]# ls
[root@Docker overlay2]# cd
[root@Docker ~]# rm -rf /var/lib/docker/
[root@Docker ~]# systemctl start docker
[root@Docker ~]# ls /var/lib/docker/
buildkit engine-id network plugins swarm volumes
containers image overlay2 runtimes tmp
[root@Docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@Docker ~]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Docker ~]# ls /var/lib/docker/overlay2/
backingFsBlockDev l
[root@Docker ~]# docker pull centos
[root@Docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 2 years ago 231MB
[root@Docker ~]# ls /var/lib/docker/overlay2/
995db6a0fd46ba18fca60ad04b3d2636f83cda26a9e5e007a1e2f798b0e7cc5e l
backingFsBlockDev
[root@Docker ~]# ls /var/lib/docker/overlay2/995db6a0fd46ba18fca60ad04b3d2636f83cda26a9e5e007a1e2f798b0e7cc5e/diff/
bin etc lib lost+found mnt proc run srv tmp var
dev home lib64 media opt root sbin sys usr
[root@Docker ~]# docker run -it --name c0 centos:latest /bin/bash
[root@Docker ~]# ls /var/lib/docker/overlay2/
0ae38644f8efc1a202827f54d26b77bb99cc62590530c95d42ac922c5a2e0b4a
0ae38644f8efc1a202827f54d26b77bb99cc62590530c95d42ac922c5a2e0b4a-init
995db6a0fd46ba18fca60ad04b3d2636f83cda26a9e5e007a1e2f798b0e7cc5e
backingFsBlockDev
l
[root@Docker ~]# docker exec c0 dd if=/dev/zero of=/nuli.txt bs=10M count=100
[root@Docker ~]# ls /var/lib/docker/overlay2/0ae38644f8efc1a202827f54d26b77bb99cc62590530c95d42ac922c5a2e0b4a
diff link lower merged work
[root@Docker ~]# ls /var/lib/docker/overlay2/0ae38644f8efc1a202827f54d26b77bb99cc62590530c95d42ac922c5a2e0b4a/merged/
bin etc lib lost+found mnt opt root sbin sys usr
dev home lib64 media nuli.txt proc run srv tmp var
1.在docker daemo初始状态(没有镜像的时候)/var/lib/docker不存在
2.当docker daemon服务器启动,会自动创建dock目录
3.在没有镜像的情况下。查看overlay2这个目录是只有两个文件,管道文件,1目录(管理镜像和容器的软连接的目录)4.当我们pul一个镜像之后 /a r/lib/docker/overlay2下就有一个新的目录,这个目录就是cenonos的基础目录,这个新的目录就是镜像,就是不可读的层
三、基础镜像的制作
#打包镜像
tar --numeric-owner --exclude=/proc --exclude=/sys -cvf linux_project.tar /
ls -lh linux_project.tar
docker import -m "山不向我走来,我便向山走去" linux_project zm:v0
ls /var/lib/docker/overlay2/
docker run -it --name zm01 zm:v0 /bin/bash
cd /etc/yum.repos.d/
ls
[root@Docker ~]# docker run -it --name c0 centos:latest /bin/bash
[root@7554e0a69288 /]# rm -rf /etc/yum.repos.d/*
[root@7554e0a69288 /]# curl -o /etc/yum.repos.d/CentOS-Base.repo
[root@7554e0a69288 /]# yum clean all && yum makecache
[root@7554e0a69288 /]# yum -y install httpd
[root@Docker ~]# docker commit c0 centos:httpd
[root@Docker ~]# docker stop c0
[root@Docker ~]# ls /var/lib/docker/overlay2/
6be84eeb89f20e3a01ecb81e31d978dc64a50177463452476ccab40da29a4b30
995db6a0fd46ba18fca60ad04b3d2636f83cda26a9e5e007a1e2f798b0e7cc5e
backingFsBlockDev
da0766199952ddfbd3fbd776006ce5cc13ea2f10e6c8e7e59410903fdd2f85b3
da0766199952ddfbd3fbd776006ce5cc13ea2f10e6c8e7e59410903fdd2f85b3-init
l
[root@Docker ~]# docker rm c0
[root@Docker ~]# ls /var/lib/docker/overlay2/
6be84eeb89f20e3a01ecb81e31d978dc64a50177463452476ccab40da29a4b30
995db6a0fd46ba18fca60ad04b3d2636f83cda26a9e5e007a1e2f798b0e7cc5e #镜像
backingFsBlockDev
l
[root@Docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos httpd 8c4ea681706e 2 minutes ago 280MB
centos latest 5d0da3dc9764 2 years ago 231MB