线上考试系统部署
1.部署前端服务器
1.#将资源上传到服务器
scp -r dist/ [email protected]:~
2.#创建基础容器,在服务器上
systemctl start docker.service
docker pull centos
docker run -it --name c0 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 pq
7.#导出tar包
docker export -o centos_nginx c0
8.#引入tar包
docker import -m "哈哈哈哈" centos_nginx centos:nginx
9.#查看镜像[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos nginx 1d646637a7be 5 minutes ago 309MB
centos httpd 4bec8f3517a5 2 days ago 309MB
centos yum 3e62c6e9639e 2 days ago 260MB
mysql latest a82a8f162e18 4 weeks ago 586MB
centos 7 eeb6ee3f44bd 2 years ago 204MB
centos latest 5d0da3dc9764 2 years ago 231MB10.停用c0容器
11.创建新的centos nginx容器,在创建的同时指定端口,以及挂载目录
docker run -it --name c0 -p80:80/tcp -v /opt/:/usr/share/nginx/html/ centos:nginx /bin/bash
12. 在容器内启动nginx服务
nginx
ctrl pq
13.在宿主机吧dist目录中的文件复制到opt目录下
cp -r dist/* /opt/
[root@Docker ~]# systemctl start docker
[root@Docker ~]# docker images
[root@Docker ~]# docker run -it --name mysql0 mysql:latest /bin/bash
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 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
docker run -d --name m0 -e MYSQL_ROOT_PASSWORD=ROOT -p3306:3306 mysql:latest
[root@Docker ~]# docker exec -it m0 mysql -uroot -proot
打开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>
[root@docker ~]# docker run -it --name c0 centos:latest /bin/bash
[root@1af712185b25 /]# date
Mon Aug 26 06:37:10 UTC 2024
[root@1af712185b25 /]# [root@docker ~]#
[root@docker ~]#
[root@docker ~]# docker run -it --name c2 -v /etc/localtime:/etc/localtime centos:latest /bin/bash
[root@e03355f41739 /]# date
Mon Aug 26 14:39:45 CST 2024
[root@Docker ~]# docker exec c2 ls /
[root@Docker ~]# docker exec c2 yum -y install nginx
--link 容器名:别名
(1)docker容器的ip地址是不固定,如果要作为服务器使用,就必须能够直接访问服务,不能直接使用ip,为容器设置域名,做端口映射也能保证,确定是一旦停用之后端口被占用,就无法再次启动了
(2)docker run --link 容器的名称或者是id:自定义域名
(3)被link容器必须处于启动状态,否则当前容器无法启动
[root@docker ~]# docker run -d --name m0 -e MYSQL_ROOT_PASSWORD=root mysql:latest
a9f02618c6e0374724981c2f580216905c8c9e6017e5c7fc6b03a2c7390ed1bb
[root@docker ~]# docker inspect m0
[root@docker ~]# docker run -it --name c0 --link m0:mysqldb centos:latest /bin/bash
[root@f96f5b7aaf11 /]# 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.101 ms
64 bytes from mysqldb (172.17.0.2): icmp_seq=2 ttl=64 time=0.057 ms
^C
--- mysqldb ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.057/0.079/0.101/0.022 ms
[root@f96f5b7aaf11 /]# 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 a9f02618c6e0 m0
172.17.0.3 f96f5b7aaf11
[root@docker ~]# docker attach c0
[root@f96f5b7aaf11 /]# 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.116 ms
64 bytes from mysqldb (172.17.0.4): icmp_seq=2 ttl=64 time=0.064 ms
64 bytes from mysqldb (172.17.0.4): icmp_seq=3 ttl=64 time=0.110 ms
^C
--- mysqldb ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.064/0.096/0.116/0.025 ms
[root@f96f5b7aaf11 /]# 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 a9f02618c6e0 m0
172.17.0.3 f96f5b7aaf11
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的基础目录,这个新的目录就是镜像,就是不可读的层
[root@docker ~]# tar --numeric-owner --exclude=/proc --exclude=/sys -cvf chz.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/
[root@docker ~]# ls /var/lib/docker/overlay2/
1fa42f0dd6c5d6777ecd80bf3f8e7847d2a459ca00ea469ffb90b508cc9d756c l
backingFsBlockDev
[root@docker ~]# docker run -it --name c0 centos:latest /bin/bash
[root@c8c1cbd4870e /]# rm -rf /etc/yum.repos.d/*
[root@c8c1cbd4870e /]# yum.renos.d/cent0s-Base.https://mire00com/repo/Centos-vault-8.5.2111.repo
[root@c8c1cbd4870e /]# [root@docker ~]#
[root@docker ~]# docker commit --help
[root@docker ~]# docker commit c0 centos:httpd
sha256:fdbcbead81da292bcfdb634769c76c57c0cb43bd1b2a43f6a0647d899299367f
[root@docker ~]# docker stop c0
c0
[root@docker ~]# ls /var/lib/docker/overlay2/
1fa42f0dd6c5d6777ecd80bf3f8e7847d2a459ca00ea469ffb90b508cc9d756c
44a64673b12c80f36ba21694dfc2eb999400677b012a9ef1aea5ac7d992fa166
9e59296b00ccccbf0f8007d9aa2f8bed8fbc5cc1e1f03f05bcdbc06db5c5996f
9e59296b00ccccbf0f8007d9aa2f8bed8fbc5cc1e1f03f05bcdbc06db5c5996f-init
backingFsBlockDev
l
[root@docker ~]# docker rm c0
c0
[root@docker ~]# ls /var/lib/docker/overlay2/
1fa42f0dd6c5d6777ecd80bf3f8e7847d2a459ca00ea469ffb90b508cc9d756c backingFsBlockDev
44a64673b12c80f36ba21694dfc2eb999400677b012a9ef1aea5ac7d992fa166 l
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos httpd fdbcbead81da About a minute ago 280MB
centos latest 5d0da3dc9764 2 years ago 231MB
[root@docker ~]#