Earlier, we used Docker to simply deploy the SpringBoot project and introduced what Dockerfile is. 1. Install docker-composeEnvironment CentOS 7 //Download docker-compose curl -L "https://get.daocloud.io/docker/compose/releases/download/1.27.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose //Add executable permissions to the file, otherwise the root user does not have permission chmod +x /usr/local/bin/docker-compose //Check whether the installation is successful [root@SJS local]# docker-compose --version docker-compose version 1.27.3, build 4092ae5d Common commands #Build, create, and start related containers docker-compose up -d #Stop all related containers docker-compose stop #List all container information docker-compose ps 2. Deployment Steps
3. Deploy SpringBoot projectOverall project 1. Write Dockerfile FROM java:8 # Create a container volume in the docker container for data storage and persistence VOLUME /tmp #Used to copy files and decompress (COPY cannot decompress) #Copy the current redpacket-backend-1.0.0-SNAPSHOT.jar to the root directory of the docker container ADD redpacket-backend-1.0.0-SNAPSHOT.jar app.jar #Create an app.jar file during the run process RUN sh -c 'touch /app.jar' ENV JAVA_OPTS="" #Execute the Linux command with the passed parameters to start the jar package #The difference between CMD is that only the last one of multiple CMD commands will take effect, and CMD will be replaced by the parameters after docker run #The command executed by ENTRYPOINT will be appended and will not overwrite ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 2. Write the docker-compose.yml file
version: '3.8' services: #mysql service name mysql: #Image used: mysql:5.7 command: --default-authentication-plugin=mysql_native_password ports: -3306:3306 environment: MYSQL_ROOT_HOST: '%' MYSQL_ROOT_PASSWORD: '123456' MYSQL_ALLOW_EMPTY_PASSWORD: 'no' MYSQL_DATABASE: 'redpacket' MYSQL_USER: 'root' MYSQL_PASSWORD: '123456' #File volumes that need to be mounted: - /mydata/mysql/data:/var/lib/mysql - /mydata/mysql/log:/var/log/mysql - /mydata/mysql/conf:/etc/mysql restart: always networks: -test_network #SpringBoot project service redpacket: container_name: redpacket #Build the Dockerfile in the specified directory build: context: . dockerfile: Dockerfile depends_on: -mysql ports: - "8090:8090" restart: always networks: -test_network networks: test_network: 3. Pay attention to modifying the yml file link name 4. Start the project with one click Put the project's dockerfile, docker-compose.yml, and jar package in the same directory and start it using docker-compose It succeeded 4. Pitfalls If you modify the Dockerfile during use, Reference articles: https://mp.weixin.qq.com/s/iMl9bJ4SxUsNHBbiS5VUcw https://docs.docker.com/compose/env-file/ https://blog.csdn.net/u011943534/article/details/81392993 This is the end of this article about Docker compose deployment of SpringBoot project to connect to MySQL. For more relevant Docker compose deployment of SpringBoot project content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Use CSS's clip-path property to display irregular graphics
>>: Front-end advanced teaching you to use javascript storage function
Copy code The code is as follows: <pre> <...
I encountered this problem when I was making the ...
I didn't use MySQL very often before, and I w...
Install TomCat on Windows This article will intro...
The browser is probably the most familiar tool fo...
1. When to execute setUp We all know that vue3 ca...
Find the problem I recently encountered a problem...
Multi-way search tree Height of a complete binary...
<br />Original text: http://andymao.com/andy...
Table of contents 1: Introduction to galera-clust...
1. Download the virtual machine Official download...
This article uses examples to illustrate the prin...
Table of contents 1. MySQL time type 2. Check the...
Recently, Oracle announced the public availabilit...
As an entry-level Linux user, I have used simple ...