前言
本系列介绍如何基于docker-compose部署一套自己的开发环境。
教程讲解docker中mariadb配置。
给大家上一套我自己的简单的学习环境配置~先!
https://github.com/FRBoiling/rendu-env
my.cnf
my.cnf 为mariadb必须的配置文件在 conf文件夹下,内容如下:
# The 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
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
Dockerfile
# FROM mysql:latest
FROM mariadb:latest
LABEL rendu <419610242@qq.com>
docker-compose.yml
version: "3.9"
networks:
inner: #自定义网络
name: network_inner # 指定一个自定义网络名称,而不是生成的默认名称。
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
gateway: 172.20.0.1 #网关地址
services:
mariadb:
container_name: rd_mariadb
image: boiling/mariadb:latest
restart: always
cap_add:
- ALL
build:
context: .
dockerfile: Dockerfile
ports:
- 3306:3306
environment: # 添加环境变量
MARIADB_ROOT_PASSWORD: root # root 密码
MYSQL_ROOT_HOST: '%' # root 允许登录的host
TIME_ZONE: Asia/Shanghai # 时区
volumes: # 挂载外置配置文件
- "/etc/localtime:/etc/localtime"
- "./conf:/etc/mysql/conf.d"
- "./logs:/var/log/mysql"
- "./data:/var/lib/mysql"
# - "/rendu-env/dockers/mysql/sql/init.sql:/docker-entrypoint-initdb.d/init.sql"
networks:
aliases:
- MYSQL_URL
run.sh
#!/bin/bash
#docker-compose -f docker-compose.yml up -d
docker-compose up -d