diff --git a/Dockerfile b/Dockerfile index ae08307..028ba31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,18 +3,16 @@ WORKDIR /app # 将Gradle的配置文件复制到镜像中 COPY gradlew . -COPY gradle gradle COPY build.gradle . COPY settings.gradle . - COPY src src # 构建应用 -RUN gradle bootJar +RUN ./gradlew bootJar # 使用官方的Java运行时作为最终的运行环境 FROM openjdk:17-jdk-slim WORKDIR /app -COPY --from=build/libs /app/build/libs/*.jar app.jar +COPY --from=build /app/build/libs/*.jar app.jar # 设置应用运行的端口 EXPOSE 8080 diff --git a/docker-compose.yml b/docker-compose.yml index cd2ea84..91e1efb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: restart: always environment: MYSQL_ROOT_PASSWORD: example - MYSQL_DATABASE: mydb + MYSQL_DATABASE: paopao MYSQL_USER: myuser MYSQL_PASSWORD: mypassword volumes: diff --git a/docs/guides/spring-boot-docker.md b/docs/guides/spring-boot-docker.md index 5e76179..868a458 100644 --- a/docs/guides/spring-boot-docker.md +++ b/docs/guides/spring-boot-docker.md @@ -11,13 +11,12 @@ WORKDIR /app # 将Gradle的配置文件复制到镜像中 COPY gradlew . -COPY gradle gradle COPY build.gradle . COPY settings.gradle . COPY src src # 构建应用 -RUN gradle bootJar +RUN /app/gradlew bootJar # 使用官方的Java运行时作为最终的运行环境 FROM openjdk:17-jdk-slim @@ -75,7 +74,8 @@ services: - "8080:8080" depends_on: - db - + environment: + - SPRING_PROFILES_ACTIVE=prod volumes: dbdata: ``` diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 15ab256..d51f950 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -8,8 +8,8 @@ spring: datasource: url: jdbc:mysql://db:3306/paopao?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true # MySQL连接URL,paopao是数据库名 driverClassName: com.mysql.cj.jdbc.Driver # MySQL的Driver类名 - username: root # MySQL用户名 - password: root # MySQL密码 + username: myuser # MySQL用户名 + password: mypassword # MySQL密码 jpa: show-sql: true