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