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

How to configure NAS on Windows Server 2019

Preface This tutorial installs the latest version...

HTML code to add icons to transparent input box

I was recently writing a lawyer recommendation we...

Linux server quick uninstall and install node environment (easy to get started)

1. Uninstall npm first sudo npm uninstall npm -g ...

How to implement data persistence using the vuex third-party package

Purpose: Allow the state data managed in vuex to ...

js to realize the function of uploading pictures

The principle of uploading pictures on the front ...

How to dynamically modify container port mapping in Docker

Preface: Docker port mapping is often done by map...

MySQL 5.7.18 Green Edition Download and Installation Tutorial

This article records the detailed process of down...

Sample code for implementing dark mode with CSS variables

Recently, WeChat was forced by Apple to develop a...

Summary of the application of transition components in Vue projects

​Transtion in vue is an animation transition enca...

Vue data responsiveness summary

Before talking about data responsiveness, we need...

About the garbled problem caused by HTML encoding

Today a junior student asked a question. The HTML...

WebWorker encapsulates JavaScript sandbox details

Table of contents 1. Scenario 2. Implement IJavaS...

IDEA uses the Docker plug-in (novice tutorial)

Table of contents illustrate 1. Enable Docker rem...

Writing High-Quality Code Web Front-End Development Practice Book Excerpts

(P4) Web standards are composed of a series of sta...