Docker Compose mysql导入.sql [英] Docker Compose mysql import .sql

查看:1239
本文介绍了Docker Compose mysql导入.sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过docker-compose导入.sql转储文件.我已经关注了文档,这些文档显然将从docker-entrypoint-initdb.d中加载.sql文件.但是,当我运行docker-compose up时,sql文件不会复制到容器中.

I'm having trouble importing an .sql dump file with docker-compose. I've followed the docs, which apparently will load the .sql file from docker-entrypoint-initdb.d. However, when I run docker-compose up, the sql file is not copied over to the container.

我尝试用-vf标志停止容器,但这也不起作用. .yml脚本中我做错什么了吗?

I've tried stopping the containers with -vf flag, but that didn't work either. Am I doing something wrong in my .yml script?

我的撰写文件所在的根目录中的database/db-dump/目录中有dump.sql.

I have dump.sql in the directory database/db-dump/ in the root where my compose file is.

frontend:
  image: myimage
  ports:
   - "80:80"
  links:
   - mysql
mysql:
  image: mysql
  ports:
   - "3306:3306"
  environment:
    MYSQL_ROOT_PASSWORD: rootpass
    MYSQL_USER: dbuser
    MYSQL_PASSWORD: userpass
    MYSQL_DATABASE: myimage_db
  volumes:
   - ./database/db-dump:/docker-entrypoint-initdb.d

推荐答案

在对卷设置进行了多次尝试之后,我找到了解决方法

After many attempts with the volumes setting i found a workaround

我在Dockerfile中使用以下内容创建了另一个基于mysql的映像

I created another image based on mysql with the following in the Dockerfile

FROM mysql:5.6

ADD dump.sql /docker-entrypoint-initdb.d

然后从组合中删除卷并运行新图像

Then removed the volumes from compose and ran the new image

frontend:
  image: myimage
  ports:
   - "80:80"
  links:
   - mysql
mysql:
  image: mymysql
  ports:
   - "3306:3306"
  environment:
    MYSQL_ROOT_PASSWORD: rootpass
    MYSQL_USER: dbuser
    MYSQL_PASSWORD: userpass
    MYSQL_DATABASE: myimage_db

这样,转储总是被复制并在启动时运行

This way the dump is always copied over and run on startup

这篇关于Docker Compose mysql导入.sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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