私信  •  关注

szx

szx 最近回复了
4 月前
回复了 szx 创建的主题 » 将MySQL数据存储在图像文件中(格式为ext4)

我通过使用 privileged docker-compose.yml中的选项:

privileged: true

(或) --privileged 在docker命令中)

这是我最后的docker-compose.yml:

version: '3'
services:
  db:
    build: ./db
    image: my_db
    container_name: db
    privileged: true
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
    volumes:
      - ${MYSQL_DATA_IMG}:/data.img
    restart: always

文档文件:

FROM mariadb

COPY my-custom.cnf /etc/mysql/conf.d/custom.cnf

COPY run.sh /usr/local/bin/run-mariadb.sh
ENTRYPOINT ["run-mariadb.sh"]

以及执行的自定义入口点脚本 mount (运行.sh):

#!/bin/sh

# For this mount comamnd to work the DB container must be started
# with --privileged.
mount -o loop /data.img /var/lib/mysql

# Call the entry point script of MariaDB image.
exec /usr/local/bin/docker-entrypoint.sh mysqld