使用docker-compose安装mariadb

4 篇文章 0 订阅
  • step1: 创建目录

    mkdir -p /server/mariadb/{config,data,log}
    chmod -R 777 /server/mariadb
    
  • step2: 编写docker-compose.yml

    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

    docker exec -it mariadb1 bash
    

    此时目录树:

    - server/
    - mariadb/
        - data/
        - log/
        - config/
            - my.cnf
        - docker-compose.yml
    
    # 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/
    
    
  • step4: 运行启动

    docker-compose up -d
    
要在Docker使用docker-compose安装MariaDB 10.5,你可以按照以下步骤进行操作: 1. 确保你的系统已经安装Dockerdocker-compose。如果没有安装,你可以参考官方文档进行安装。 2. 创建一个新的目录,并在该目录下创建一个名为`docker-compose.yml`的文件。 3. 在`docker-compose.yml`文件中,添加以下内容: ```yaml version: '3' services: mariadb: image: mariadb:10.5 restart: always environment: MYSQL_ROOT_PASSWORD: your_root_password volumes: - ./data:/var/lib/mysql ``` 在上面的配置中,我们使用MariaDB 10.5的官方Docker镜像,并设置了MySQL的root密码。你需要将`your_root_password`替换为你自己的密码。 此外,我们还将MariaDB的数据目录`/var/lib/mysql`映射到了本地的`./data`目录,这样可以确保数据持久化。 4. 保存并关闭`docker-compose.yml`文件。 5. 打开终端,进入到包含`docker-compose.yml`文件的目录。 6. 运行以下命令启动MariaDB容器: ``` docker-compose up -d ``` 这将下载并启动MariaDB容器。第一次启动可能需要一些时间来完成初始化。 7. 当容器启动成功后,你可以使用任何MySQL客户端连接到MariaDB。只需使用主机名`localhost`,端口号为`3306`,用户名为`root`,密码为你在`docker-compose.yml`中设置的密码。 这样,你就成功使用docker-compose安装MariaDB 10.5。希望对你有所帮助!如果你有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Spaceack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值