docker-compose:每次重新初始化MySQL数据库 [英] docker-compose: reinitializing MySQL db every time

查看:199
本文介绍了docker-compose:每次重新初始化MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个将MySQL作为数据库的Rails应用程序. docker-compose.yml db 部分看起来像

We have a Rails app with MySQL as DB. The db part of docker-compose.yml looks like

  db:
    image: mysql
    env_file:
      - ma.env
    volumes:
      - ./dump-db:/docker-entrypoint-initdb.d
      - ./my.cnf:/etc/mysql/my.cnf
    restart: always
    ports:
      - "3306:3306"
    environment:
            - MYSQL_HOST=

./dump-db 文件夹下,实际上是我们数据库的sql-dump.

and under ./dump-db folder there actually is an sql-dump of our db.

问题是,每次运行 docker-compose up 时,我们都需要加载正确的转储.MySQL docker镜像以这种方式工作,它将数据存储在主机上,因此您的db-service并非无状态.

Problem is, we need to have that exact dump loaded each and every time docker-compose up is run. MySQL docker image works in such a way, that it stores it's data on host machine and therefore your db-service is not stateless.

我们需要的是, db 服务丢弃了在 docker-compose up 之前运行中所做的所有更改,并从该确切转储重新开始

What we need is that db service discarded all changes done within docker-compose up previous run and fresh-started with that exact dump.

推荐答案

已解决

实际上,上面的想法使我对RTM有一些见识,然后就行了

actually, ideas above gave me some insight to RTM and here goes

  • 获取自己的MySQL Dockerfile
  • 从其中删除VOLUME行它提到/var/lib/mysql 应该安装在主机上.
  • docker-compose up --force-recreate db
  • Get your own MySQL Dockerfile
  • Remove the VOLUME line from it, where it mentions that /var/lib/mysql should be mounted on host.
  • docker-compose up --force-recreate db

这篇关于docker-compose:每次重新初始化MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆