Docker-compose项目应用

作者:行癫(盗版必究) ------ ## 一:环境准备 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" 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 ```