Recently, I need to package the project for members to test, but the packaged operation will affect the development. So I plan to use Since the original project was too large, I planned to try it out with a large software engineering experiment. The large software engineering experiment used docker-compose The We all know that an application container can be created using a
The service is Build spring-boot To compile
Build the #### Build spring-boot project FROM openjdk:8-jdk-alpine as build # Set the project working directory WORKDIR /app in the docker container # Copy the Maven executable program into the container COPY mvnw . COPY .mvn .mvn # Copy pom.xml file COPY pom.xml . # Import all Maven dependencies RUN ./mvnw dependency:go-offline -B # Copy the project source code COPY src src # Package the application RUN ./mvnw package -DskipTests RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar) #### Set the minimum docker container that can run the application FROM openjdk:8-jre-alpine ARG DEPENDENCY=/app/target/dependency # Copy project dependencies from the build stage COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app ENTRYPOINT ["java","-cp","app:app/lib/*","com.xiang.airTicket.AirTicketApplication"] Docker-compose integrated project services After completing the spring-boot container construction, you can use
version: '3.7' # Define services: # spring-boot service app-server: build: context: . #Configure the path to build the Dockerfile relative to docker-compose.yml dockerfile: Dockerfile ports: - "8080:8080" # Map local port 8080 to container port 8080 restart: always depends_on: -db # The dependent services need to be built first - redis environment: #Set environment variables SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/airTicket?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false SPRING_DATASOURCE_USERNAME: root SPRING_DATASOURCE_PASSWORD: 123456 SPRING_REDIS.HOST: redis networks: # Network connection mysql and redis - backend db: image:mysql:5.6 ports: - "3306:3306" restart: always environment: MYSQL_DATABASE: airTicket MYSQL_USER: htx MYSQL_PASSWORD: 123456 MYSQL_ROOT_PASSWORD: 123456 volumes: -db-data:/var/lib/mysql networks: - backend redis: image: redis command: [ "redis-server", "--protected-mode", "no" ] hostname: redis ports: - "6379:6379" networks: - backend volumes: db-data: networks: backend: Use Start the container using When you see the log of successful spring-boot startup, it is successfully configured. Follow-up This time, I only built the backend. I hope to build the frontend Reference link: Spring Boot, Mysql, React docker compose example The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Vue uses three methods to refresh the page
>>: Causes and solutions for MySQL master-slave synchronization delay
This article shares the specific code of Vue to i...
This article shares the specific code for WeChat ...
In the previous article, I introduced how to solv...
Table of contents 1. Demand 2. Database Design 3....
Table of contents Table definition auto-increment...
Automatically discover disks Configuration Key Va...
The <tfoot> tag is used to define the style...
Table of contents Preface Idea startup speed Tomc...
Use the Vue-Cropper component to upload avatars. ...
If you cannot download it by clicking downloadlao...
Table of contents 1. Definition of stack 2. JS st...
W3C recently released two standards, namely "...
Table of contents Preface 1. Extract data 2. Alia...
In the web pages we make, if we want more people ...
Closures are one of the traditional features of p...