docker-compose deployment project based on MySQL8

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 the 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

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
3. Follow the path below to create the corresponding folder
/usr/local/docker/tomcat
4. Create a docker-compose.yml under the directory of the folder and fill in the relevant configuration information (since the 8080 port of the above host machine is occupied, it can only be changed 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 you can't start it, you can try it directly with the start command
docker run -p 8082:8080 镜像id或者镜像名称
6.Unzip the project and upload it to the same directory as tomcat and then run it to achieve deployment

Explanation:

  1. A container can deploy a project, it is not very strange, if I deploy three applications on the same server, a front-end UI, a back-end Admin, a database MySQL, then the back-end to manage the front-end data The configuration file docker-compose is as follows

admain 路径:/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

docekr-compose configuration

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

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

How does the back-end management front-end data work? In fact, the person will contact 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, it is through this ip for data management. This ip is the server ip deployed by mysql, so the connection configuration of the deployed project is all pointed to this ip, so that the background can get the data of this database and directly manage the data in the foreground. Moreover, database visualization interfaces such as Navicat and SQLyog can use the IP deployed by the database such as the above IP to easily manage the data in the server database.

  1. If you need to stop a service, you can use docker-compose down directly under the folder corresponding to that service and the directory at the same level as docker-compose to directly stop a service
Published 19 original articles · Like 7 · Visitor 6629

Guess you like

Origin blog.csdn.net/William_TWG/article/details/85804591
Recommended