环境描述
系统:centos7.8
组件 | 版本 |
---|---|
docker | 20.10.6 |
docker-compose | v2.2.2 |
mariadb | 10.5.10 |
docker安装传送门:https://www.cnblogs.com/inclme/p/15829349.html
docker-compose安装传送门:https://www.cnblogs.com/inclme/p/15829558.html
创建持久化目录
[root@localhost ~]# mkdir -p /root/component/mariadb/{data,conf}
创建mariadb.cnf和my.cnf
[root@localhost ~]# docker run --name=mariadb -d mariadb:10.5.10
Unable to find image 'mariadb:10.5.10' locally
10.5.10: Pulling from library/mariadb
c549ccf8d472: Pull complete
26ea6552a462: Pull complete
329b1f41043f: Pull complete
9f8d09317d80: Pull complete
2bc055a5511d: Pull complete
e989e430508e: Pull complete
201c98fa16f6: Pull complete
cc09fec0bce1: Pull complete
1c9b9043bdda: Pull complete
f0e596ee38c5: Pull complete
Digest: sha256:cf656762c1727a4e08d838aea95973767cb7a9f7151532f38657189ae57051cc
Status: Downloaded newer image for mariadb:10.5.10
72f77bf15b6fcc952a859c51aa6c9374a4301390fe87801c68b6a821ee4878da
[root@localhost ~]# docker cp mariadb:/etc/mysql/mariadb.cnf /root/component/mariadb/conf
[root@localhost conf]# cat my.cnf
# mariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[mysqld]
skip-grant-tables
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock
max_connections=1000
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
这里我最大连接数修改为1000,默认是100
删除临时mariadb服务
[root@localhost mariadb]# docker rm -f mariadb
mariadb
创建docker-compose文件
[root@localhost mariadb]# cat docker-compose.yml
version: '3'
services:
rebbitmq:
restart: always
image: mariadb:10.5.10
container_name: mariadb
hostname: mariadb
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: 123456
TZ: Asia/Shanghai
volumes:
- /etc/localtime:/etc/localtime
- /root/component/mariadb/data:/var/lib/mysql
- /root/component/mariadb/conf/mariadb.cnf:/etc/mysql/mariadb.cnf
- /root/component/mariadb/conf/my.cnf:/etc/mysql/my.cnf
[root@localhost mariadb]# docker-compose up -d
[+] Running 1/1
⠿ Container mariadb Started