Docker笔记-DB(mariadb)

前言

本系列介绍如何基于docker-compose部署一套自己的开发环境。
教程讲解docker中mariadb配置。
给大家上一套我自己的简单的学习环境配置~先!
https://github.com/FRBoiling/rendu-env
image.png

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
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值