更新 'Docker-compose-MD/Docker-compose应用项目.md'

This commit is contained in:
diandian 2023-03-27 01:04:20 +08:00
parent b5559f5186
commit 389199d405
1 changed files with 88 additions and 88 deletions

View File

@ -1,88 +1,88 @@
<h1><center>Docker-compose项目应用</center></h1>
作者:行癫(盗版必究)
------
## 一:环境准备
1.docker环境
2.docker-compose环境
3.jar包
注意:
该案例主要是网络的配置network创建网络使用网络
该案例主要是links使用相当于本地服务器域名解析
项目在连接数据库时可以在docker-compose使用links连接hostname项目中数据库地址改为hostname的值
该项目配置了数据库在docker-compose文件中直接导入官方Dockerfile中有专门的目录和执行脚本
## 二Docker-compose
#### 1.准备
![image-20230327004541931](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20230327004541931.png)
#### 2.Dockerfile文件
```shell
[root@nfs-harbor a]# cat Dockerfile
FROM centos:7
MAINTAINER "xingdian" <xingdian@gmail.com>
ENV TZ=Asia/Shanghai
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ADD jdk-8u211-linux-x64.tar.gz /usr/local/
RUN mv /usr/local/jdk1.8.0_211 /usr/local/java
ENV JAVA_HOME /usr/local/java/
ENV PATH $PATH:$JAVA_HOME/bin
COPY mayday.jar /usr/local
EXPOSE 10086
CMD java -jar /usr/local/mayday.jar
```
#### 3.Docker-compose文件
```shell
[root@nfs-harbor a]# cat docker-compose.yml
version: "3.1"
networks:
xingdian:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
services:
db.com:
container_name: db
image: mysql:5.7.38
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: maydaytest
hostname: db.com
networks:
- xingdian
volumes:
- /etc/localtime:/etc/localtime
- ./mysql:/var/lib/mysql
- ./mayday.sql:/docker-entrypoint-initdb.d/mayday.sql
web.com:
container_name: web
build: .
hostname: web.com
networks:
- xingdian
ports:
- 30090:8091
links:
- db.com
```
<h1><center>Docker-compose项目应用</center></h1>
作者:行癫(盗版必究)
------
## 一:环境准备
1.docker环境
2.docker-compose环境
3.jar包
注意:
该案例主要是网络的配置network创建网络使用网络
该案例主要是links使用相当于本地服务器域名解析
项目在连接数据库时可以在docker-compose使用links连接hostname项目中数据库地址改为hostname的值
该项目配置了数据库在docker-compose文件中直接导入官方Dockerfile中有专门的目录和执行脚本
## 二Docker-compose
#### 1.准备
![image-20230327004541931](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20230327004541931.png)
#### 2.Dockerfile文件
```shell
[root@nfs-harbor a]# cat Dockerfile
FROM centos:7
MAINTAINER "xingdian" <xingdian@gmail.com>
ENV TZ=Asia/Shanghai
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ADD jdk-8u211-linux-x64.tar.gz /usr/local/
RUN mv /usr/local/jdk1.8.0_211 /usr/local/java
ENV JAVA_HOME /usr/local/java/
ENV PATH $PATH:$JAVA_HOME/bin
COPY mayday.jar /usr/local
EXPOSE 10086
CMD java -jar /usr/local/mayday.jar
```
#### 3.Docker-compose文件
```shell
[root@nfs-harbor a]# cat docker-compose.yml
version: "3.1"
networks:
xingdian:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
services:
db.com:
container_name: db
image: mysql:5.7.38
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: maydaytest
hostname: db.com
networks:
- xingdian
volumes:
- /etc/localtime:/etc/localtime
- ./mysql:/var/lib/mysql
- ./mayday.sql:/docker-entrypoint-initdb.d/mayday.sql
web.com:
container_name: web
build: .
hostname: web.com
networks:
- xingdian
ports:
- 30090:8091
links:
- db.com
```