Spring Boot + MYSQL + Docker的配置 - DEV
使用 docker-compose 使用 Spring Boot 和 MYSQL 資料庫進行 CRUD 操作。
在 application.properties 檔案中新增了 Mysql 配置。
spring.jpa.show-sql = true server.port=8084 spring.application.name=property-service # MYSQL Config spring.jpa.hibernate.ddl-auto=create-drop spring.datasource.url=jdbc:mysql://mysql-db:3306/property?createDatabaseIfNotExist=true spring.datasource.username=root spring.datasource.password=spring spring.datasource.driver-class-name =com.mysql.cj.jdbc.Driver spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.datasource.initialization-mode=never |
docker-compose.yml:
version: '3.3' services: service 1: definition of mysql database db: image: mysql:latest container_name: mysql-db environment: - MYSQL_ROOT_PASSWORD=spring ports: - "3306:3306" restart: always service 2: definition of phpMyAdmin phpmyadmin: image: phpmyadmin/phpmyadmin:latest container_name: my-php-myadmin ports: - "8082:80" restart: always depends_on: - db environment: SPRING_DATASOURCE_USERNAME: root SPRING_DATASOURCE_PASSWORD: spring service 3: definition of your spring-boot app customerservice: it is just a name, which will be used only in this file. image: property-service name of the image after dockerfile executes container_name: property-service-app name of the container created from docker image build: context: . docker file path (. means root directory) dockerfile: Dockerfile docker file name ports: - "8084:8084" docker containter port with your os port restart: always depends_on: define dependencies of this app - db dependency name (which is defined with this name 'db' in this file earlier) environment: SPRING_DATASOURCE_URL: jdbc:mysql://mysql-db:3306/property?createDatabaseIfNotExist=true SPRING_DATASOURCE_USERNAME: root SPRING_DATASOURCE_PASSWORD: spring |
Dockerfile配置:
FROM openjdk:11 as mysqldoc EXPOSE 8084 WORKDIR /app # Copy maven executable to the image COPY mvnw . COPY .mvn .mvn # Copy the pom.xml file COPY pom.xml . # Copy the project source COPY ./src ./src COPY ./pom.xml ./pom.xml RUN chmod 755 /app/mvnw RUN ./mvnw dependency:go-offline -B RUN ./mvnw package -DskipTests RUN ls -al ENTRYPOINT ["java","-jar","target/springboot-demo-mysql-0.0.1-SNAPSHOT.jar"] |
相關文章
- Spring Boot 2.0(五):Docker Compose + Spring Boot + Nginx + Mysql 實踐Spring BootDockerNginxMySql
- Spring Boot:Spring Boot配置MybatisSpring BootMyBatis
- Spring Boot:Spring Boot配置SwaggerSpring BootSwagger
- Spring Boot 整合 dockerSpring BootDocker
- Spring Boot Demo with DockerSpring BootDocker
- Spring Boot 2.0(四):使用 Docker 部署 Spring BootSpring BootDocker
- Spring Boot & 配置Spring Boot
- 使用 Docker 部署 Spring BootDockerSpring Boot
- Spring Boot 建立 Docker 映象Spring BootDocker
- spring boot 配置 JPASpring Boot
- Spring Boot核心配置Spring Boot
- Spring boot學習(二) Spring boot基礎配置Spring Boot
- Spring Boot學習筆記:Spring Boot核心配置Spring Boot筆記
- 減少Spring Boot的JVM記憶體佔用的Docker三種配置Spring BootJVM記憶體Docker
- 使用Spring Boot建立docker imageSpring BootDocker
- Spring Boot配置類的註解Spring Boot
- 詳解Spring Boot的RedisAutoConfiguration配置Spring BootRedis
- Spring Boot 配置檔案Spring Boot
- Spring Boot中配置 AuditListenerSpring Boot
- spring boot 配置外接tomcatSpring BootTomcat
- Spring Boot Security配置教程Spring Boot
- Spring Boot 配置介面 WebMvcConfigurerSpring BootWebMVC
- Spring Boot 支援 JSP配置Spring BootJS
- 【Spring Boot】yaml配置注入Spring BootYAML
- Spring Boot日誌配置Spring Boot
- Spring boot學習(八)Spring boot配置ehcache快取框架Spring Boot快取框架
- Spring boot學習(九)Spring boot配置郵件傳送Spring Boot
- spring boot基於Java的容器配置Spring BootJava
- Spring Boot日誌的使用和配置Spring Boot
- Spring Boot的配置檔案管理技巧Spring Boot
- 使用 Docker 部署 Spring Boot 專案DockerSpring Boot
- 使用Docker部署Spring Boot專案DockerSpring Boot
- Spring Boot + Mybatis + Spring MVC環境配置(三):DataSource配置Spring BootMyBatisMVC
- 基於Java11最小化Spring Boot 2 的Docker映象檔案配置JavaSpring BootDocker
- Spring Boot Reactor Netty配置 | BaeldungSpring BootReactNetty
- Spring Boot logback日誌配置Spring Boot
- Spring Boot 自動配置原理Spring Boot
- Spring Boot + MongoDB 應用的 Docker 化實踐Spring BootMongoDBDocker