Implementation of docker-compose deployment project based on MySQL8

Implementation of docker-compose deployment project based on MySQL8

1. First, create the corresponding folder according to the following path

/usr/local/docker/mysql

2. Then create a docker-compose.yml file in this directory and add the following configuration to the file

version: '3.1'
services:
 db:
  image: mysql
  restart: always
  environment:
   MYSQL_ROOT_PASSWORD: 123456
  command:
   --default-authentication-plugin=mysql_native_password
   --character-set-server=utf8mb4
   --collation-server=utf8mb4_general_ci
   --explicit_defaults_for_timestamp=true
   --lower_case_table_names=1
   --max_allowed_packet=128M;
  ports:
   -3306:3306
  volumes:
   - ./data:/var/lib/mysql

 admin:
  image: adminer
  restart: always
  ports:
   - 8080:8080

3. Create the corresponding folder according to the following path

/usr/local/docker/tomcat

4. Create a docker-compose.yml file in the directory of the folder and fill in the relevant configuration information (since the 8080 port of the host machine above is occupied, you can only change it to another port here)

version: '3.1'
services:
 tomcat:
  restart: always
  image: tomcat
  container_name: tomcat
  ports:
   -8082:8080
  volumes:
   - /usr/local/docker/tomcat:/usr/local/tomcat/webapps/ROOT
  environment:
   TZ: Asia/Shanghai

Note: If the created directories are different, the corresponding /usr/local/docker/tomcat directories above cannot be the same

5. If it fails to start, you can try it directly with the startup command

docker run -p 8082:8080 image id or image name

6. Upload the project to the same directory as tomcat, unzip it and run it to achieve deployment

illustrate:

One container can deploy one project, so isn't it strange? If I deploy three applications on the same server, a front-end UI, a back-end Admin, and a database MySQL, then the back-end needs to manage the front-end data, and their configuration files docker-compose are as follows

admain path: /usr/local/docker/tomcat

version: '3.1'
services:
 tomcat:
  restart: always
  image: tomcat
  container_name: tomcat
  ports:
   -8082:8080
  volumes:
   - /usr/local/docker/tomcat:/usr/local/tomcat/webapps/ROOT
  environment:
   TZ: Asia/Shanghai

UI: /usr/local/docker/tomcat_ui

version: '3.1'
services:
 tomcat:
  restart: always
  image: tomcat
  container_name: tomcatui
  ports:
   -8083:8080
  volumes:
   - /usr/local/docker/tomcat_ui:/usr/local/tomcat/webapps/ROOT
  environment:
   TZ: Asia/Shanghai~

mysql path: /usr/local/docker/mysql

Configuration of docekr-compose

version: '3.1'
services:
 db:
  image: mysql
  restart: always
  environment:
   MYSQL_ROOT_PASSWORD: 123456
  command:
   --default-authentication-plugin=mysql_native_password
   --character-set-server=utf8mb4
   --collation-server=utf8mb4_general_ci
   --explicit_defaults_for_timestamp=true
   --lower_case_table_names=1
  ports:
   -3306:3306
  volumes:
   - ./data:/var/lib/mysql

 admin:
  image: adminer
  restart: always
  ports:
   - 8080:8080

How does the backend manage the front-end data? In fact, it depends on the project you deployed. There is a data connection configuration in the project as follows

JDBC
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql://192.168.206.128:3306/twg?useUnicode=true&characterEncoding=utf-8&useSSL=false
jdbc.username=root
jdbc.password=123456
# JDBC Pool
jdbc.pool.init=1
jdbc.pool.minIdle=3
jdbc.pool.maxActive=20
JDBC Test
jdbc.testSql=SELECT 'x' FROM DUAL

Then the jdbc.connectionURL=jdbc:mysql://192.168.206.128:3306/twg?useUnicode=true&characterEncoding=utf-8&useSSL=false configured here is the key. In fact, data management is carried out through this IP. This IP is the server IP deployed by MySQL, so the connection configuration of the deployed project points to this IP, so that the background can obtain the data of this database and directly manage the front-end data. Moreover, database visualization interfaces such as Navicat and SQLyog can easily manage the data in the server database using the IP deployed by the database, such as the IP above.

If you need to stop a service, you can use docker-compose down in the folder corresponding to the service and in the directory at the same level as docker-compose to stop the service directly.

This is the end of this article about the implementation of docker-compose based on MySQL8 deployment project. For more relevant content about docker-compose deployment of MySQL8, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker compose deploys SpringBoot project to connect to MySQL and the pitfalls encountered
  • How to run MySQL using docker-compose
  • Use dockercompose to build springboot-mysql-nginx application
  • A brief analysis of the problem of mysql being inaccessible when deployed with docker-compose
  • How to build an elk system using docker compose
  • Detailed process of building mongodb and mysql with docker-compose

<<:  Solution to the problem that the page is blank when opening the page with source file in IE7

>>:  Let's talk about the issue of passing parameters to React onClick

Recommend

MySql multi-condition query statement with OR keyword

The previous article introduced the MySql multi-c...

Self-study of MySql built-in functions knowledge points summary

String functions Check the ascii code value of th...

Detailed explanation of basic concepts of HTML

What is HTML? HTML is a language used to describe...

Tkinter uses js canvas to achieve gradient color

Table of contents 1. Use RGB to represent color 2...

MySQL 8.0.11 installation and configuration method graphic tutorial (win10)

This article records the installation and configu...

Detailed explanation of Vue data proxy

Table of contents 1. What I am going to talk abou...

Docker installs Redis and introduces the visual client for operation

1 Introduction Redis is a high-performance NoSQL ...

Detailed explanation of custom instructions for Vue.js source code analysis

Preface In addition to the default built-in direc...

Automatically log out inactive users after login timeout in Linux

Method 1: Modify the .bashrc or .bash_profile fil...

The whole process of installing gogs with pagoda panel and docker

Table of contents 1 Install Docker in Baota Softw...

4 ways to modify MySQL root password (summary)

Method 1: Use the SET PASSWORD command First log ...