如何在构建时创建填充的MySQL Docker镜像 [英] How to create populated MySQL Docker Image on build time

查看:148
本文介绍了如何在构建时创建填充的MySQL Docker镜像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想创建3个图层,如下所示:

  | --------------------- | ------------ --------- 
Layer 3 |客户1数据库|客户2数据库|
| --------------------- | --------------------- |
Layer 2 |数据库图像与表,但没有数据|
| ------------------------------------------- |
Layer 1 | mysql:5.6.26 |
| ------------------------------------------- |

现在我的问题是如何为第2层和第3层创建一个正确的Dockerfile?
其中我的empty_with_tables.sql文件加载到第2层,customer1.sql和customer2.sql加载到第3层中的两个图像。我读了一些关于将SQL文件放入'/docker-entrypoint-initdb.d' 。但是这将导致在第一次启动图像时的数据。这不是我想要的。我希望数据在映像中准备就绪(例如,在测试中快速可用)。



我可以启动mysql镜像,从命令行加载数据a'commit',但这是不可重现的,需要在SQL文件中的数据更改时再次执行。



如何实现?



最好的问候,




  • Morten Green Hermansen

$所以我的解决方案这个问题只是不是层的一切,但创建一个基础镜像,并使用--volumes-from注入数据库文件从一个数据专用容器。


I would like to create a MySQL Docker image with data already populated.

I want to create 3 layers like this:

        |---------------------|---------------------|
Layer 3 | Customer 1 Database | Customer 2 Database |
        |---------------------|---------------------|
Layer 2 |   Database image with tables but no data  |
        |-------------------------------------------|
Layer 1 |                mysql:5.6.26               |
        |-------------------------------------------|

My question is now how to create a correct Dockerfile for layer 2 and 3? Where my empty_with_tables.sql file is loaded into layer 2 and customer1.sql and customer2.sql is loaded into two images in layer 3. I read something about putting SQL files into '/docker-entrypoint-initdb.d'. But this would result in the data being when the image is started for the first time. This not what I want. I want the data to be ready in the image (for example to be quickly available in testing).

I could start the mysql image, load the data from commandline and do a 'commit' but this is not reproducible, requiring doing that again when data in the SQL files are changed.

How can this be done?

Best regards,

  • Morten Green Hermansen

解决方案

So my solution to this problem was just NOT to layer everything but create a base image and use --volumes-from to inject the database files from a data-only container.

这篇关于如何在构建时创建填充的MySQL Docker镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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