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
Table of contents vuex persistence Summarize vuex...
Common scenarios for Nginx forwarding socket port...
It took me three hours to install MySQL myself. E...
Table of contents 1. Easy to use 2. Using generic...
Table of contents Preface keep-avlive hook functi...
This article example shares the specific code for...
1. Introduction Recently, I helped a friend to ma...
1. Grammar: <meta name="name" content...
1. Introduction The difference between row locks ...
Copy code The code is as follows: <object id=&...
Table of contents Preface Reference Comparison Ma...
The effect of this function is similar to vue的pro...
We hope to insert the weather forecast into the w...
First, let me explain that what we want to do is ...
Table of contents 1. Pull the image 2. Create a l...