In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Recently, we need to package the project for members to test, but it affects the development after running, so we intend to use docker to simulate the production environment to run the packaged project, so that we can both develop and test for members.
As the original project is too large, I intend to try the water with the big experiment of software engineering first. The big experiment of software engineering uses the environment of spring-boot,redis,mysql,angular,nginx. I first try the docker construction of spring-boot,redis,mysql in the background.
Docker-compose
The compose project is the official open source project of Docker, which is responsible for the rapid orchestration of Docker container clusters. Compose positioning is an application that defines and runs multiple docker containers.
We all know that you can create an application container using a Dockerfile template file, but usually in a project, you need multiple application containers, just like my background, as well as jdk8, redis, and mysql applications. Docker-compose just meets this need. It allows users to define a set of associated application containers as a project through a separate docker-compose.yml template file.
Two important concepts in compose:
Service (service): a container for an application that can actually include several container instances running the same image.
Project (project): a complete business unit consisting of a set of associated application containers, defined in the docker-compose.yml file.
The service is the docker container we need, and the project is made up of many services. After learning about docker-compose, we can build the environment.
Set up spring-boot
To compile spring-boot, based on the following process:
Copy the mvnw and pom.xml under spring-boot into the container based on the jdk8 image, import the maven dependency to copy the source code under the src directory into the container, package the spring-boot project with maven and run the project using the jre8 environment.
Built Dockerfile file:
# establish spring-boot project FROM openjdk:8-jdk-alpine as build# setup project working directory in docker container WORKDIR / app# copy maven executable program into container COPY mvnw .COPY .mvn .mvn # copy pom.xml file COPY pom.xml. # Import all maven dependent RUN. / mvnw dependency:go-offline-B # copy project source code COPY src src# packaged application RUN. / Mvnw package-DskipTestsRUN mkdir-p target/dependency & & (cd target/dependency Jar-xf.. / * .jar) # set the minimum docker container FROM openjdk:8-jre-alpineARG DEPENDENCY=/app/target/dependency# Copy project dependencies from the build stageCOPY-- from=build ${DEPENDENCY} / BOOT-INF/lib / app/libCOPY-- from=build ${DEPENDENCY} / META-INF / app/META-INFCOPY-- from=build ${DEPENDENCY} / BOOT-INF/classes / appENTRYPOINT ["java", "- cp", "app:app/lib/*", "com.xiang.airTicket.AirTicketApplication"]
Docker-compose Integration Project Services
Once you have completed the container construction for spring-boot, you can use docker-compose to integrate spring-boot, redis, and mysql containers. Specific ideas:
Declare the services that the project needs to integrate
Docker-compose.yml file:
Version: '3.7 services # define service services: # spring-boot service app-server: build: context:. # configure the path to build Dockerfile relative to docker-compose.yml dockerfile: Dockerfile ports:-"8080Dockerfile ports" # Map native port 8080 to container port 8080 restart: always depends_on:-db # build the dependent service first-redis environment: # set the environment variable 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 airTicket MYSQL_USER 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 networks:-backend volumes: db-data:networks: backend:
Use docker-compose build to build the project container:
Start the container using docker-compose up:
When you successfully see the log of the successful startup of spring-boot, it is successfully configured.
Follow up
This time, only the background is built. I hope to finish building the angular and nginx of the foreground, fight for a docker command, and start the application directly.
Reference links: Spring Boot, Mysql, React docker compose example
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.