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
WeChat applet: Simple calculator, for your refere...
Table of contents Scenario Core Issues Status mon...
Table of contents Message Board Required librarie...
After the changes: innodb_buffer_pool_size=576M -...
Table of contents Preface Reference Comparison Ma...
I just bought an Alibaba Cloud host and couldn’t ...
This article shares the specific code of js to re...
This article example shares the specific code of ...
Table of contents 1. The simplest example 2. Cust...
Since my local MySQL version is relatively low, I...
Login + sessionStorage Effect display After a suc...
This article shares with you the solution to the ...
Table of contents 1. Subquery definition 2. Subqu...
Time fields are often used in database usage. Com...
background Today, while cooperating with other pr...