8月30日笔记
项目实战:使用docker部署project-exam-system
1、背景:
使用基础的docker指令来创建镜像,实现项目的发布,使用Dockderfile,docker compose编排容器。
2、环境准备:
(1)主机 dokcer01(192.168.2.80)
(2)部署docker环境,执行脚本,参照之前的文章
[root@dokcer01 ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
[root@dokcer01 ~]#systemctl restart docker
3、普通部署
#####前端:nginx latest服务######
# 拉取nginx镜像
[root@dokcer01 ~]#docker pull nginx
[root@dokcer01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 5ef79149e0ec 2 weeks ago 188MB
centos latest 5d0da3dc9764 2 years ago 231MB
# 创建nginx容器
[root@dokcer01 ~]# docker run -itd -p80:80 nginx:latest
f4905bfc0a85b7d61b6b0e5e67332ad53283d39a9dac37be209e25db69fe5624
[root@dokcer01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4905bfc0a85 nginx:latest "/docker-entrypoint.…" 8 seconds ago Up 8 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp practical_keldysh
# 访问测试
[root@dokcer01 ~]# curl localhost
# 查看资源文件
[root@dokcer01 ~]# docker ps
[root@dokcer01 ~]# docker exec -it f4905bf ls /usr/share/nginx/html
# 创建目录,不单独放置前端的资料,将后端所有资料都放在此处 mkdir
[root@dokcer01 ~]# mkdir project_exam_system
[root@dokcer01 ~]# cd project_exam_system/
[root@dokcer01 project_exam_system]# mkdir web
[root@dokcer01 project_exam_system]# ls web/dist/
assets favicon.ico index.html
# 停掉并移除容器
[root@dokcer01 project_exam_system]# docker stop f4905b
f4905b
[root@dokcer01 project_exam_system]# docker rm f4905bf4905b
f4905b
# 再创建容器(映射端口及挂载目录)
[root@dokcer01 ~]# docker run -itd centos:latest /bin/bash
675fca4c734a3abce237dae8391a507f2ac2be6438a318b083788f04af01d78c
# 测试成功,但出现问题,实现登录的时候出现后端异常,因为还没部署后端
# 设置域名劫持,在真机的hosts文件中添加域名来实现登录的时候请求的域名ks.tangpin.huajuan
#####后端:jdk17 springboot(不单独部署tomcat,已经在springboot中内置tomcat)######
# 拉取基础centos镜像
[root@dokcer01 project_exam_system]# docker pull centos
# jdk17版本文件
[root@dokcer01 project_exam_system]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 5ef79149e0ec 2 weeks ago 188MB
centos latest 5d0da3dc9764 2 years ago 231MB
# 启动镜像生成容器
[root@dokcer01 ~]# docker run -itd centos:latest /bin/bash
675fca4c734a3abce237dae8391a507f2ac2be6438a318b083788f04af01d78c
# 上传项目并移动资源文件,application.properties和Project_ExamSystem-V1.0.0.war,先上传到/root下,再移动到dokcer中
[root@docker~]#scp -r dist/ root@192.168.2.80:~/project_exam_system/web/
[root@dokcer01 ~]# ls
anaconda-ks.cfg
application.properties
docker.sh
huajuan.tar
jdk-17_linux-x64_bin.tar.gz
project_exam_system
Project_ExamSystem-V1.0.0.war
Soft
[root@dokcer01 ~]# docker cp application.properties 675fca:/
Successfully copied 4.1kB to 675fca:/
[root@dokcer01 ~]# docker cp Project_ExamSystem-V1.0.0.war 675fca:/
Successfully copied 41MB to 675fca:/
[root@dokcer01 ~]# docker cp jdk-17_linux-x64_bin.tar.gz 675fca:/
Successfully copied 183MB to 675fca:/
# 检查是否移动成功
[root@dokcer01 ~]# docker attach 675fca
[root@675fca4c734a /]# ls
Project_ExamSystem-V1.0.0.war lib64 sbin
application.properties lost+found srv
bin media sys
dev mnt tmp
etc opt usr
home proc var
jdk-17_linux-x64_bin.tar.gz root
lib
# 跳过一层目录进行解压
[root@675fca4c734a /]# mkdir /usr/local/jdk
[root@675fca4c734a /]# tar -zxvf jdk-17_linux-x64_bin.tar.gz -C /usr/local/jdk/ --strip-components=1
# 修改application文件
[root@675fca4c734a /]# vi application.properties
spring.datasource.url=jdbc:mysql://192.168.2.80:3306/project_exam_system
【宿主机ip】 【数据库名称】
spring.datasource.username=zhangmin
spring.datasource.password=zhangmin
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 启动服务
[root@675fca4c734a /]# /usr/local/jdk/bin/java -jar Project_ExamSystem-V1.0.0.war
# 测试
[root@dokcer01 ~]# curl 192.168.2.80:8080
# 使用容器创建镜像
[root@dokcer01 ~]# docker commit 675fca java:v0
sha256:e9e25e9b727960b24f09a0ad7736abacb2f4d9cd9bf02a2164deeee7862c71eb
[root@dokcer01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java v0 e9e25e9b7279 5 seconds ago 775MB
nginx latest 5ef79149e0ec 2 weeks ago 188MB
centos latest 5d0da3dc9764 2 years ago 231MB
[root@dokcer01 ~]# docker stop 675fca
675fca
[root@dokcer01 ~]# docker rm 675fca
675fca
[root@dokcer01 ~]# docker run -itd -p8080:80 java:v0
c4cbff0183e0fa8c49e5cad170f30a6dc01d93a1f23c6ebe9874af9547d78614
# 查看进程
[root@dokcer01 ~]#docker ps
[root@dokcer01 ~]# docker attach c4cbff
[root@dokcer01 /]# /usr/local/jdk/bin/java -jar Proje
ct_ExamSystem-V1.0.0.war
遇到的报错!!!
docker:Error response from daemon:driver failed programming external connectivity on endpoint xxxx
例如:来自daemon的错误响应:驱动程序在端点上的外部连接编程失败
解决方案:
# 测试,显示账号密码不存在,出现500表明java服务配置成功
[root@dokcer01 ~]# curl 192.168.2.80:8080
{"code":20002,"msg":"账号不存在或密码错误"}[root@dokcer01 ~]#
#####mysql服务######
# 拉取mysql:5.7.44
[root@dokcer01 ~]#docker pull mysql:5.7.44
[root@dokcer01 ~]# docker images
mysql 5.7.44 5107333e08a8 8 months ago 501MB
# 上传sql语句到/root目录下
[root@dokcer01 ~]# ls
project_exam_system.sql
# 启动数据库
[root@dokcer01 ~]#docker run -itd -e MYSQL_ROOT_PASSWORD=ROOT -p 3306:3306 mysql:5.7.44
01f24510a17fde44cab63bfb13ac7c55cf8f0a7bdfbbc038bae059d0eff0a466
# 查看所有容器
[root@dokcer01 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01f24510a17f mysql:5.7.44 "docker-entrypoint.s…" 15 seconds ago Up 13 seconds
# 取出/data目录数据库
[root@dokcer01 ~]# docker cp 01f24:/var/lib/mysql project_exam_system/
Successfully copied 220MB to /root/project_exam_system/
[root@dokcer01 ~]# cd project_exam_system/
[root@dokcer01 project_exam_system]# ls
mysql web
[root@dokcer01 project_exam_system]# cd mysql/
# 删除存在的mysql目录,重新创建mysql目录
[root@dokcer01 mysql]# rm -rf mysql/
[root@dokcer01 mysql]# mkdir mysql
[root@dokcer01 mysql]# ls
[root@dokcer01 mysql]# mv project_exam_system.sql mysql/
[root@dokcer01 mysql]# ls mysql/
project_exam_system.sql
[root@dokcer01 mysql]# pwd
/root/project_exam_system/mysql
# 将sql上传到mysql容器中
[root@dokcer01 ~]# docker cp project_exam_system/mysql/project_exam_system.sql 01f24:/
Successfully copied 11MB to 01f24:/
ebf32bf6e6b3e52521355cbc1fa6b0a3fa3acb01740d68363bc9a1768ae26d6d
[root@dokcer01 ~]# docker attach 01f24
# 使用exec指令访问数据库管理界面,查看是否有数据库
[root@dokcer01 ~]#mysql -uroot -proot < project_exam_system.sql
# 启动mysql容器并映射端口
docker run -itd -p3306:3306 mysql:5.7.44
[root@dokcer01 ~]#docker exec -it 01f24 mysql -uroot -root
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 -ADatabase changed
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 |
mysql> create user 'huajuan'@'%' identified by 'huajuan';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on *.* to 'huajuan'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
#####使用Dockerfile文件进行编排######
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
48fd8551ec83 mysql:5.7.44 "docker-entrypoint.s…" 27 minutes ago Up 27 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp flamboyant_nash
d3a039010bf1 java:v0 "/bin/bash" 4 hours ago Up 4 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quirky_bell
7c7f8bbb4ae7 nginx:latest "/docker-entrypoint.…" 5 hours ago Up 5 hours 0.0.0.0:80->80/tcp, :::80->80/tcp thirsty_babbage
[root@docker01 ~]# ls
anaconda-ks.cfg jdk-17_linux-x64_bin.tar.gz Project_ExamSystem-V1.0.0.war
application.properties mysql
docker.sh project_exam_system
[root@docker01 ~]# mkdir project_exam_system/java
[root@docker01 ~]# mv jdk-17_linux-x64_bin.tar.gz project_exam_system/java/
[root@docker01 ~]# mv application.properties project_exam_system/java/
[root@docker01 ~]# mv Project_ExamSystem-V1.0.0.war project_exam_system/java/
[root@docker01 ~]# ls
anaconda-ks.cfg docker.sh mysql project_exam_system
[root@docker01 ~]# tree -L 3 project_exam_system/
project_exam_system/
├── java
│ ├── application.properties
│ ├── jdk-17_linux-x64_bin.tar.gz
│ └── Project_ExamSystem-V1.0.0.war
├── mysql
│ └── project_exam_system.sql
└── web
├── dist
│ ├── assets
│ ├── favicon.ico
│ └── index.html
└── dist.zip
5 directories, 7 files
[root@docker01 ~]# cd project_exam_system/java/
[root@docker01 java]# rz -E
rz waiting to receive.
[root@docker01 java]# ls
application.properties jdk-17_linux-x64_bin.tar.gz
Dockerfile Project_ExamSystem-V1.0.0.war
[root@docker01 java]# docker build -t java:v1 .
[root@docker01 java]# ls
application.properties jdk-17_linux-x64_bin.tar.gz
Dockerfile Project_ExamSystem-V1.0.0.war
[root@docker01 java]# tar -zxvf jdk-17_linux-x64_bin.tar.gz
[root@docker01 java]# ls
application.properties jdk-17.0.12 Project_ExamSystem-V1.0.0.war
Dockerfile jdk-17_linux-x64_bin.tar.gz
[root@docker01 java]# mv jdk-17.0.12/ jdk
[root@docker01 java]# ls
application.properties jdk Project_ExamSystem-V1.0.0.war
Dockerfile jdk-17_linux-x64_bin.tar.gz
[root@docker01 java]# vim Dockerfile
[root@docker01 java]# docker build -t java:v1 .
[+] Building 5.5s (9/10) docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 405B 0.0s
=> [internal] load metadata for docker.io/library/centos:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/7] FROM docker.io/library/centos:latest 0.0s
=> [internal] load build context 3.6s
=> => transferring context: 318.73MB 3.6s
=> CACHED [2/7] ADD application.properties /application.properties 0.0s
=> [3/7] ADD jdk/ /usr/local/jdk/ 1.2s
=> [4/7] ADD Project_ExamSystem-V1.0.0.war /Project_ExamSystem-V1.0.0.war 0.2s
=> ERROR [5/7] RUN mkdir /usr/local/jdk 0.4s
------
> [5/7] RUN mkdir /usr/local/jdk:
0.361 mkdir: cannot create directory '/usr/local/jdk': File exists
------
Dockerfile:13
--------------------
11 | EXPOSE 8080
12 |
13 | >>> RUN mkdir /usr/local/jdk
14 |
15 | RUN tar -zxvf /jdk-17_linux-x64_bin.tar.gz -C /usr/local/jdk --strip-components=1
--------------------
ERROR: failed to solve: process "/bin/sh -c mkdir /usr/local/jdk" did not complete successfully: exit code: 1
[root@docker01 java]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java v0 cf1a38ea2001 5 hours ago 774MB
nginx latest 5ef79149e0ec 2 weeks ago 188MB
mysql 5.7.44 5107333e08a8 8 months ago 501MB
centos latest 5d0da3dc9764 2 years ago 231MB
[root@docker01 java]# vim Dockerfile
[root@docker01 java]# docker build -t java:v1 .
[+] Building 2.4s (10/10) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 404B 0.0s
=> [internal] load metadata for docker.io/library/centos:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/7] FROM docker.io/library/centos:latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 25.82kB 0.0s
=> CACHED [2/7] ADD application.properties /application.properties 0.0s
=> [3/7] ADD jdk/ /usr/loca/jdk/ 1.2s
=> [4/7] ADD Project_ExamSystem-V1.0.0.war /Project_ExamSystem-V1.0.0.war 0.2s
=> [5/7] RUN mkdir /usr/local/jdk 0.4s
=> ERROR [6/7] RUN tar -zxvf /jdk-17_linux-x64_bin.tar.gz -C /usr/local/jdk - 0.4s
------
> [6/7] RUN tar -zxvf /jdk-17_linux-x64_bin.tar.gz -C /usr/local/jdk --strip-components=1:
0.306 tar (child): /jdk-17_linux-x64_bin.tar.gz: Cannot open: No such file or directory
0.306 tar (child): Error is not recoverable: exiting now
0.308 tar: Child returned status 2
0.308 tar: Error is not recoverable: exiting now
------
Dockerfile:15
--------------------
13 | RUN mkdir /usr/local/jdk
14 |
15 | >>> RUN tar -zxvf /jdk-17_linux-x64_bin.tar.gz -C /usr/local/jdk --strip-components=1
16 |
17 | CMD [ "/usr/local/jdk/bin/java -jar Project_ExamSystem-V1.0.0.war" ]
--------------------
ERROR: failed to solve: process "/bin/sh -c tar -zxvf /jdk-17_linux-x64_bin.tar.gz -C /usr/local/jdk --strip-components=1" did not complete successfully: exit code: 2
[root@docker01 java]# vim Dockerfile
[root@docker01 java]# docker build -t java:v1 .
[+] Building 0.4s (9/9) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 321B 0.0s
=> [internal] load metadata for docker.io/library/centos:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/6] FROM docker.io/library/centos:latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 25.82kB 0.0s
=> CACHED [2/6] ADD application.properties /application.properties 0.0s
=> CACHED [3/6] ADD jdk /usr/local/jdk/ 0.0s
=> CACHED [4/6] ADD Project_ExamSystem-V1.0.0.war /Project_ExamSystem-V1.0.0. 0.0s
=> ERROR [5/6] RUN mkdir /usr/local/jdk 0.3s
------
> [5/6] RUN mkdir /usr/local/jdk:
0.246 mkdir: cannot create directory '/usr/local/jdk': File exists
------
Dockerfile:13
--------------------
11 | EXPOSE 8080
12 |
13 | >>> RUN mkdir /usr/local/jdk
14 |
15 | CMD [ "/usr/local/jdk/bin/java -jar Project_ExamSystem-V1.0.0.war" ]
--------------------
ERROR: failed to solve: process "/bin/sh -c mkdir /usr/local/jdk" did not complete successfully: exit code: 1
[root@docker01 java]# vim Dockerfile
[root@docker01 java]# docker build -t java:v1 .
[+] Building 2.2s (9/9) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 295B 0.0s
=> [internal] load metadata for docker.io/library/centos:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/5] FROM docker.io/library/centos:latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 25.82kB 0.0s
=> CACHED [2/5] ADD application.properties /application.properties 0.0s
=> CACHED [3/5] ADD jdk /usr/local/jdk/ 0.0s
=> CACHED [4/5] ADD Project_ExamSystem-V1.0.0.war /Project_ExamSystem-V1.0.0. 0.0s
=> exporting to image 2.0s
=> => exporting layers 2.0s
=> => writing image sha256:8738b8a36bf97b7066911888fcc6ccfde793b4f42892be3fe7 0.0s
=> => naming to docker.io/library/java:v1 0.0s
[root@docker01 java]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java v1 8738b8a36bf9 5 minutes ago 591MB
java v0 cf1a38ea2001 5 hours ago 774MB
nginx latest 5ef79149e0ec 2 weeks ago 188MB
mysql 5.7.44 5107333e08a8 8 months ago 501MB
centos latest 5d0da3dc9764 2 years ago 231MB
[root@docker01 java]# docker run -itd -p8080:8080 java:v1 /bin/bash
0379c12f93fc7d06c6a236fe53d3db73b8a74387eb6dac439cf3de7a0fee9073
docker: Error response from daemon: driver failed programming external connectivity on endpoint dreamy_jones (f34b58f6da48030ef97dad4802d6d0e9191c078f6f047b8b96999b0549fc8b16): Bind for 0.0.0.0:8080 failed: port is already allocated.
[root@docker01 java]# docker run -itd -p8081:8080 java:v1 /bin/bash
a3c4fbc92430316aae70755992d76c3d1d2868560f61e1cbbfb5dc57eb93cd4b
[root@docker01 java]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3c4fbc92430 java:v1 "/bin/bash" 55 seconds ago Up 55 seconds 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp heuristic_carson
0379c12f93fc java:v1 "/bin/bash" About a minute ago Created dreamy_jones
48fd8551ec83 mysql:5.7.44 "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp flamboyant_nash
d3a039010bf1 java:v0 "/bin/bash" 5 hours ago Up 5 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quirky_bell
7c7f8bbb4ae7 nginx:latest "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp thirsty_babbage
[root@docker01 java]# docker stop 037
037
[root@docker01 java]# docker rm 037
037
[root@docker01 java]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3c4fbc92430 java:v1 "/bin/bash" About a minute ago Up About a minute 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp heuristic_carson
48fd8551ec83 mysql:5.7.44 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp flamboyant_nash
d3a039010bf1 java:v0 "/bin/bash" 5 hours ago Up 5 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quirky_bell
7c7f8bbb4ae7 nginx:latest "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp thirsty_babbage
[root@docker01 java]# docker rm heuristic_carson
Error response from daemon: cannot remove container "/heuristic_carson": container is running: stop the container before removing or force remove
[root@docker01 java]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3c4fbc92430 java:v1 "/bin/bash" 2 minutes ago Up 2 minutes 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp heuristic_carson
48fd8551ec83 mysql:5.7.44 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp flamboyant_nash
d3a039010bf1 java:v0 "/bin/bash" 5 hours ago Up 5 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quirky_bell
7c7f8bbb4ae7 nginx:latest "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp thirsty_babbage
[root@docker01 java]# docker stop heuristic_carson
heuristic_carson
[root@docker01 java]# docker rm heuristic_carson
heuristic_carson
[root@docker01 java]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
48fd8551ec83 mysql:5.7.44 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp flamboyant_nash
d3a039010bf1 java:v0 "/bin/bash" 5 hours ago Up 5 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quirky_bell
7c7f8bbb4ae7 nginx:latest "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp thirsty_babbage
[root@docker01 java]# vim Dockerfile
[root@docker01 java]# vim start.sh
[root@docker01 java]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java v1 8738b8a36bf9 33 minutes ago 591MB
java v0 cf1a38ea2001 5 hours ago 774MB
nginx latest 5ef79149e0ec 2 weeks ago 188MB
mysql 5.7.44 5107333e08a8 8 months ago 501MB
centos latest 5d0da3dc9764 2 years ago 231MB
[root@docker01 java]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
48fd8551ec83 mysql:5.7.44 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp flamboyant_nash
d3a039010bf1 java:v0 "/bin/bash" 5 hours ago Up 5 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quirky_bell
7c7f8bbb4ae7 nginx:latest "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp thirsty_babbage
[root@docker01 java]# docker rmi java:v1
Untagged: java:v1
Deleted: sha256:8738b8a36bf97b7066911888fcc6ccfde793b4f42892be3fe770551daf8365c4
[root@docker01 java]# docker build -t java:v1 .
[+] Building 0.6s (11/11) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 309B 0.0s
=> [internal] load metadata for docker.io/library/centos:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/7] FROM docker.io/library/centos:latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 25.93kB 0.0s
=> CACHED [2/7] ADD application.properties /application.properties 0.0s
=> CACHED [3/7] ADD jdk /usr/local/jdk/ 0.0s
=> CACHED [4/7] ADD Project_ExamSystem-V1.0.0.war /Project_ExamSystem-V1.0.0. 0.0s
=> [5/7] ADD start.sh /start.sh 0.0s
=> [6/7] RUN chmod -v +x /start.sh 0.4s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:cbe450fc552275f01d345fcbb348099cced02d0e5d00ae4813 0.0s
=> => naming to docker.io/library/java:v1 0.0s
[root@docker01 java]# docker run -itd -p8081:8080 java:v1
5fc4bd6c574f58aee7c7ad560e8f8189b94324369c54c0e11adb2b16e0921058
[root@docker01 java]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5fc4bd6c574f java:v1 "/start.sh /bin/bash" 12 seconds ago Up 11 seconds 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp kind_easley
48fd8551ec83 mysql:5.7.44 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp flamboyant_nash
d3a039010bf1 java:v0 "/bin/bash" 5 hours ago Up 5 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quirky_bell
7c7f8bbb4ae7 nginx:latest "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp thirsty_babbage