部署project_exam_system项目——及容器的编排

(一)安装docker、编辑daemon.json文件、安装docker-compose编排容器、启动docker

1.环境准备

bash 复制代码
[root@docker--1 ~]# rz -E
 
rz waiting to receive.
 
[root@docker--1 ~]# ls
 
anaconda-ks.cfg  docker.sh
 
[root@docker--1 ~]# source docker.sh 
 
[root@docker--1 ~]# vim /etc/docker/daemon.json 
 
[root@docker--1 ~]# vim /usr/lib/systemd/system/docker.service
 
[root@docker--1 ~]# systemctl daemon-reload
 
[root@docker--1 ~]# systemctl start docker

脚本内容如下:

bash 复制代码
cat << EOF | tee /etc/modules-load.d/k8s.conf 
overlay
br_netfilter
EOF
 
modprobe overlay
 
modprobe br_netfilter
 
cat << EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
 
sysctl --system
 
yum install -y yum-utils device-mapper-persistent-data lvm2
 
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 
 
 
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

2.普通部署

按照正常步骤安装docker,这里可参考前面的笔记

3.拉取nginx镜像

bash 复制代码
[root@docker3 ~]# docker pull nginx
 
Using default tag: latest
 
latest: Pulling from library/nginx
 
Digest: sha256:447a8665cc1dab95b1ca778e162215839ccbb9189104c79d7ec3a81e14577add
 
Status: Image is up to date for nginx:latest
 
docker.io/library/nginx:latest

4.查看镜像

bash 复制代码
[root@docker3 ~]# docker images
 
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
 
nginx        latest    5ef79149e0ec   2 weeks ago   188MB

5.创建nginx容器

[root@docker--1 ~]# docker run -itd -p80:80 nginx:latest a9200f608c60aa1c8827b5562b7906d543d48e38c06f76bdb1b702ce73209117

bash 复制代码
[root@docker--1 ~]# docker ps
 
CONTAINER ID   IMAGE          COMMAND                   CREATED          STATUS             NAMES
 
a9200f608c60   nginx:latest   "/docker-entrypoint...."   19 seconds ago   Up 17 seconds cp   stupefied_feistel

进行验证

bash 复制代码
[root@docker--1 ~]# curl localhost
 
<!DOCTYPE html>
 
<html>
 
<head>
 
<title>Welcome to nginx!</title>
 
<style>
 
html { color-scheme: light dark; }
 
body { width: 35em; margin: 0 auto;
 
font-family: Tahoma, Verdana, Arial, sans-serif; }
 
</style>
 
</head>
 
<body>
 
<h1>Welcome to nginx!</h1>
 
<p>If you see this page, the nginx web server is successfully installed and
 
working. Further configuration is required.</p>
 
<p>For online documentation and support please refer to
 
nginx.org.<br/>
 
Commercial support is available at
 
nginx.com.</p>
 
<p><em>Thank you for using nginx.</em></p>
 
</body>
 
</html>

注:容器启动后nginx服务就自动发布了,浏览器也能够看到nginx页面

(二)部署project_exam_system项目

创建一个目录,放置前端和后端的资料

[root@docker--1 ~]# mkdir project_exam_system

切入到所创建的目录中

[root@docker--1 ~]# cd project_exam_system/

创建web目录

[root@docker--1 project_exam_system]# mkdir web

切入到web目录下

[root@docker--1 project_exam_system]# cd web/

拖拽dist.zip的压缩包

bash 复制代码
[root@docker--1 web]# rz -E
 
rz waiting to receive.
 
[root@docker--1 web]# ls
 
dist.zip

安装unzip

[root@docker--1 web]# yum -y install unzip

使用unzip进行解压dist.zip的包

bash 复制代码
[root@docker--1 web]# unzip dist.zip 
 
[root@docker--1 web]# ls
 
dist  dist.zip
 
[root@docker--1 web]# cd ..

停止并删除前面所创建的容器

停止容器

[root@docker--1 project_exam_system]# docker stop a92

a92

删除容器

[root@docker--1 project_exam_system]# docker rm a92

a92

创建容器,进行映射端口和挂载目录

bash 复制代码
[root@docker--1 project_exam_system]# docker run -itd -p80:80 -v /root/project_exam_syml/ nginx:latest 
 
7c7f8bbb4ae732042b9ad3060d58f5c595f76fd7348b2b8e5beea857f74cf6e2

浏览器访问

采用域名劫持设置域名

顾名思义也就是修改物理机上的hosts文件来达到效果

修改hosts文件

后端业务jdk17、springboot

bash 复制代码
 
 
#拉取centos镜像
 
[root@docker--1 project_exam_system]# docker pull centos
 
#回到根目录
 
[root@docker--1 project_exam_system]# cd
 
#拖拽项目资源和jdk17版本的文件
 
#项目资源:application.properties
 
 		      Project_ExamSystem-V1.0.0.war
 
#jdk17版本的文件:  jdk-17_linux-x64_bin.tar.gz  
 
		
 
[root@docker--1 ~]# rz -E
rz waiting to receive.
[root@docker--1 ~]# rz -E
rz waiting to receive.
[root@docker--1 ~]# rz -E
rz waiting to receive.
 
#查看 
 
[root@docker--1 ~]# ls
anaconda-ks.cfg         docker.sh                    project_exam_system
application.properties  jdk-17_linux-x64_bin.tar.gz  Project_ExamSystem-V1.0.0.war
 
#使用centos镜像创建容器
 
[root@docker--1 ~]# docker run -it centos:latest /bin/bash
 
#使用ctrl p+q退出
 
[root@2267541087e9 /]# [root@docker--1 ~]# 
 
#查看容器
 
[root@docker--1 ~]# docker ps
CONTAINER ID   IMAGE           COMMAND                   CREATED          STATUS          PORTS                               NAMES
2267541087e9   centos:latest   "/bin/bash"               44 seconds ago   Up 43 seconds                                       hardcore_raman
7c7f8bbb4ae7   nginx:latest    "/docker-entrypoint...."   34 minutes ago   Up 34 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   thirsty_babbage
 
#将在服务器上的java文件上传到容器
 
[root@docker--1 ~]# docker cp jdk-17_linux-x64_bin.tar.gz 226:/
Successfully copied 183MB to 226:/
[root@docker--1 ~]# docker cp application.properties 226:/
Successfully copied 4.1kB to 226:/
[root@docker--1 ~]# docker cp Project_ExamSystem-V1.0.0.war 226:/
Successfully copied 41MB to 226:/
 
#对已经传到容器的文件进行部署
 
 
[root@docker--1 ~]# docker attach 226
 
[root@2267541087e9 /]# ls    
Project_ExamSystem-V1.0.0.war  home			    media  run	 usr
application.properties	       jdk-17_linux-x64_bin.tar.gz  mnt    sbin  var
bin			       lib			    opt    srv
dev			       lib64			    proc   sys
etc			       lost+found		    root   tmp
 
#创建目录
 
[root@2267541087e9 /]# mkdir /usr/local/jdk
 
 
 
[root@2267541087e9 /]# tar -zxvf jdk-17_linux-x64_bin.tar.gz -C /usr/local/jdk/ --strip-components=1
 
 
 
 
[root@2267541087e9 /]# vi application.properties 
 
spring.datasource.url=jdbc:mysql://192.168.1.24:3306/project exam system
spring.datasource.username=dd
spring.datasource.password=1
spring,datasource.driver-class-name=com.mysal.cj.jdbc.Driver
 
[root@2267541087e9 /]# /usr/local/jdk/bin/java -jar Project_ExamSystem-V1.0.0.war 
 
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.3.2)
 running for 8.671)
read escape sequence
[root@docker--1 ~]# curl 172.17.0.3:8080
{"code":20002,"msg":"账号不存在或密码错误"}[root@docker--1 ~]# 
[root@docker--1 ~]# docker commit 226 java:v0
sha256:cf1a38ea2001eac37d139eaa9d76899aed7e3521fcd7c07588edcf705f817add
[root@docker--1 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
java         v0        cf1a38ea2001   8 seconds ago   774MB
nginx        latest    5ef79149e0ec   2 weeks ago     188MB
centos       latest    5d0da3dc9764   2 years ago     231MB
[root@docker--1 ~]# docker ps
CONTAINER ID   IMAGE           COMMAND                   CREATED             STATUS             PORTS                               NAMES
2267541087e9   centos:latest   "/bin/bash"               38 minutes ago      Up 38 minutes                                          hardcore_raman
7c7f8bbb4ae7   nginx:latest    "/docker-entrypoint...."   About an hour ago   Up About an hour   0.0.0.0:80->80/tcp, :::80->80/tcp   thirsty_babbage
[root@docker--1 ~]# docker stop 226
226
[root@docker--1 ~]# docker rm 226
[root@docker--1 ~]# docker run -itd -p8080:8080 java:v0 
d3a039010bf133b0dffa280664274d517f2c149d751ab45883d3dfc08dc2f5cc
[root@docker--1 ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                   CREATED             STATUS             PORTS                                       NAMES
d3a039010bf1   java:v0        "/bin/bash"               12 seconds ago      Up 11 seconds      0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   quirky_bell
7c7f8bbb4ae7   nginx:latest   "/docker-entrypoint...."   About an hour ago   Up About an hour   0.0.0.0:80->80/tcp, :::80->80/tcp           thirsty_babbage
[root@docker--1 ~]# docker attach d3a
[root@d3a039010bf1 /]# /usr/local/jdk/bin/java -jar Project_ExamSystem-V1.0.0.war 
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 
 :: Spring Boot ::                (v3.3.2)
 
running for 8.057)
read escape sequence
ctrl p+q退出
[root@docker--1 ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                   CREATED             STATUS             PORTS                                       NAMES
d3a039010bf1   java:v0        "/bin/bash"               11 minutes ago      Up 11 minutes      0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   quirky_bell
7c7f8bbb4ae7   nginx:latest   "/docker-entrypoint...."   About an hour ago   Up About an hour   0.0.0.0:80->80/tcp, :::80->80/tcp           thirsty_babbage

浏览器访问

bash 复制代码
#拉取mysql镜像
[root@docker--1 ~]# docker pull mysql:5.7.44
#创建容器,指定端口映射
[root@docker--1 ~]# docker run -itd -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:5.7.44
48fd8551ec838b218bd853bb49e99fb4650ebd3c22a93d214a2cc64941eae141
#查看容器
[root@docker--1 ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                   CREATED          STATUS          PORTS                                                  NAMES
48fd8551ec83   mysql:5.7.44   "docker-entrypoint.s..."   15 seconds ago   Up 14 seconds   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   flamboyant_nash
d3a039010bf1   java:v0        "/bin/bash"               3 hours ago      Up 3 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
#切入到project_exam_system目录下
[root@docker--1 ~]# cd project_exam_system/
[root@docker--1 project_exam_system]# ls
project_exam_system.sql  web
#创建mysql目录
[root@docker--1 project_exam_system]# mkdir mysql
#移动文件
#将project_exam_system.sql移动到mysql目录下
[root@docker--1 project_exam_system]# mv project_exam_system.sql mysql/
#将project_exam_system.sql复制到容器
 
[root@docker--1 ~]# docker cp project_exam_system/mysql/project_exam_system.sql 48fd:/
Successfully copied 11MB to 48fd:/
#查看镜像
 
[root@docker--1 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
java         v0        cf1a38ea2001   4 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@docker--1 ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                   CREATED          STATUS          PORTS                                                  NAMES
48fd8551ec83   mysql:5.7.44   "docker-entrypoint.s..."   13 minutes ago   Up 13 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   flamboyant_nash
d3a039010bf1   java:v0        "/bin/bash"               3 hours ago      Up 3 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@docker--1 ~]# docker exec -it 48fd mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.44 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
 
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  |
| 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> 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 'dd'@'%' identified by '1';
Query OK, 0 rows affected (0.01 sec)
 
mysql> grant all on *.* to 'dd'@'%';
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
[root@docker--1 ~]# docker ps
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@docker--1 ~]# 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@docker--1 ~]# mkdir project_exam_system/java
[root@docker--1 ~]# mv jdk-17_linux-x64_bin.tar.gz project_exam_system/java/
[root@docker--1 ~]# mv application.properties project_exam_system/java/
[root@docker--1 ~]# mv Project_ExamSystem-V1.0.0.war project_exam_system/java/
[root@docker--1 ~]# ls
anaconda-ks.cfg  docker.sh  mysql  project_exam_system
[root@docker--1 ~]# 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@docker--1 ~]# cd project_exam_system/java/
[root@docker--1 java]# rz -E
rz waiting to receive.
[root@docker--1 java]# ls
application.properties  jdk-17_linux-x64_bin.tar.gz
Dockerfile              Project_ExamSystem-V1.0.0.war
[root@docker--1 java]# docker build -t java:v1 .
[root@docker--1 java]# ls
application.properties  jdk-17_linux-x64_bin.tar.gz
Dockerfile              Project_ExamSystem-V1.0.0.war
[root@docker--1 java]# tar -zxvf jdk-17_linux-x64_bin.tar.gz 
 
[root@docker--1 java]# ls
application.properties  jdk-17.0.12                  Project_ExamSystem-V1.0.0.war
Dockerfile              jdk-17_linux-x64_bin.tar.gz
[root@docker--1 java]# mv jdk-17.0.12/ jdk
[root@docker--1 java]# ls
application.properties  jdk                          Project_ExamSystem-V1.0.0.war
Dockerfile              jdk-17_linux-x64_bin.tar.gz
[root@docker--1 java]# vim Dockerfile 
[root@docker--1 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@docker--1 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@docker--1 java]# vim Dockerfile 
[root@docker--1 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@docker--1 java]# vim Dockerfile 
[root@docker--1 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@docker--1 java]# vim Dockerfile 
[root@docker--1 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@docker--1 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@docker--1 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@docker--1 java]# docker run -itd -p8081:8080 java:v1 /bin/bash
a3c4fbc92430316aae70755992d76c3d1d2868560f61e1cbbfb5dc57eb93cd4b
[root@docker--1 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@docker--1 java]# docker stop 037
037
[root@docker--1 java]# docker rm 037
037
[root@docker--1 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@docker--1 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@docker--1 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@docker--1 java]# docker stop heuristic_carson
heuristic_carson
[root@docker--1 java]# docker rm heuristic_carson
heuristic_carson
[root@docker--1 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@docker--1 java]# vim Dockerfile 
[root@docker--1 java]# vim start.sh
[root@docker--1 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@docker--1 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@docker--1 java]# docker rmi java:v1
Untagged: java:v1
Deleted: sha256:8738b8a36bf97b7066911888fcc6ccfde793b4f42892be3fe770551daf8365c4
[root@docker--1 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@docker--1 java]# docker run -itd -p8081:8080 java:v1
5fc4bd6c574f58aee7c7ad560e8f8189b94324369c54c0e11adb2b16e0921058
[root@docker--1 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
[root@docker--1 java]# 
相关推荐
运维&陈同学23 分钟前
【zookeeper01】消息队列与微服务之zookeeper工作原理
运维·分布式·微服务·zookeeper·云原生·架构·消息队列
O&REO1 小时前
单机部署kubernetes环境下Overleaf-基于MicroK8s的Overleaf应用部署指南
云原生·容器·kubernetes
运维小文2 小时前
K8S资源限制之LimitRange
云原生·容器·kubernetes·k8s资源限制
wuxingge11 小时前
k8s1.30.0高可用集群部署
云原生·容器·kubernetes
志凌海纳SmartX12 小时前
趋势洞察|AI 能否带动裸金属 K8s 强势崛起?
云原生·容器·kubernetes
锅总12 小时前
nacos与k8s service健康检查详解
云原生·容器·kubernetes
BUG弄潮儿12 小时前
k8s 集群安装
云原生·容器·kubernetes
Code_Artist12 小时前
Docker镜像加速解决方案:配置HTTP代理,让Docker学会科学上网!
docker·云原生·容器
何遇mirror13 小时前
云原生基础-云计算概览
后端·云原生·云计算
颜淡慕潇14 小时前
【K8S系列】kubectl describe pod显示ImagePullBackOff,如何进一步排查?
后端·云原生·容器·kubernetes