使用docker-compose安装mariadb

2020-11-04 14:33:13 浏览数 (1)

step1: 创建目录

代码语言:javascript复制
mkdir -p /server/mariadb/{config,data,log}
chmod -R 777 /server/mariadb

step2: 编写docker-compose.yml

代码语言:javascript复制
version: '3.1'
services:
  mariadb:
    image: mariadb:10.5.5
    container_name: "mariadb1"
    restart: always
    environment:
      MYSQL_USER: "root"
      MYSQL_PASSWORD: "123456"
      MYSQL_ROOT_PASSWORD: "123456"
      TZ: "Asia/Shanghai"
    ports:
      - "3306:3306"
    volumes:
      - ./data:/var/lib/mysql
      - ./log:/var/log/mysql
      - ./conf/my.cnf:/etc/mysql/my.cnf

step3: 拷贝/etc/mysql/my.cnf 到 /server/mariadb/conf/my.cnf

代码语言:javascript复制
docker exec -it mariadb1 bash

此时目录树:

代码语言:javascript复制
- server/
- mariadb/
    - data/
    - log/
    - config/
        - my.cnf
    - docker-compose.yml

step4: 运行启动

代码语言:javascript复制
docker-compose up -d

0 人点赞