Directory Structure . │ .env │ docker-compose.yml │ └─mysql ├─config │ my.cnf │ └─data The data directory under the mysql directory is the data directory, where the mysql data tables and binary log files are located. The .env file contains some variables that can be referenced in the Of course, you can also put the mysql directory somewhere else, but here, for convenience, I put it directly in the same directory as the yml file. .env File MYSQL_ROOT_PASSWORD=root MYSQL_ROOT_HOST=% MYSQL_DIR=./mysql MySQL configuration file my.cnf [mysqld] character-set-server=utf8mb4 default-time-zone='+8:00' innodb_rollback_on_timeout='ON' max_connections=500 innodb_lock_wait_timeout=500 If using the default configuration, this file can be omitted. docker-compose.yml version: '3' services: mysql-db: container_name: mysql-docker # Specify the name of the container image: mysql:8.0 # Specify the image and version ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_ROOT_HOST: ${MYSQL_ROOT_HOST} volumes: - "${MYSQL_DIR}/data:/var/lib/mysql" #Mount data directory - "${MYSQL_DIR}/config:/etc/mysql/conf.d" #Mount configuration file directory Environment variables
Running the container Execute in the docker-compose.yml directory: To run in the background, use Stop the container: If it is running in the foreground, use: Ctrl + C to stop. Both methods will delete the container after stopping, and the up command must be used to start it next time. Stop but do not delete the container: After stopping with the stop command, restart with the start command. Summarize The above is the method of running MySQL using docker-compose introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you! You may also be interested in:
|
<<: How to change the database data storage directory in MySQL
>>: vue-cropper component realizes image cutting and uploading
Linux is currently the most widely used server op...
Question: In index.html, iframe introduces son.htm...
Here are 10 tips on how to design better-usable w...
Windows 10 now supports Linux subsystem, saying g...
1. Display the files or directories in the /etc d...
Introduction to Selenium Grid Although some new f...
Table of contents 1 Introduction 2 Basic usage 2....
Preparation: 1. Install VMware workstation softwa...
I made a Dockerfile for openresty on centos7 and ...
In the horizontal direction, you can set the alig...
MySQL partitioning is helpful for managing very l...
When installing a virtual machine, a prompt appea...
Table of contents 1. Project environment: 2: DNS ...
Table of contents Functional Components How to wr...
Knowing which for loop or iterator is right for o...