在mysql容器中提交数据 [英] Commit data in a mysql container

查看:68
本文介绍了在mysql容器中提交数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了官方支持的 mysql映像创建了一个mysql容器.我运行了映像,安装了一个包含sql dump的文件夹,然后在容器中创建了一个新数据库,并在其中导入了.sql dump:

I created a mysql container using the officially supported mysql image. I ran the image mounting a folder that contains a sql dump, then I created a new database in the container and imported the .sql dump in it:

sudo docker run --name mysql-psat1 -v /opt/Projets/P1/sqldumps:/mnt -e MYSQL_ROOT_PASSWORD=secret -d mysql:latest
sudo docker exec -it mysql-psat1 bash
> mysql -uroot -psecret -e 'create database liferay_psat1;'
> mysql -uroot -psecret liferay_psat1 < /mnt/liferay_sql_dump.sql

然后我列出了正在运行的容器以获取该容器的ID:

Then I listed the running containers to get that container's id:

sudo docker ps -a

然后,我将容器(带有导入的sql)提交为新的容器映像

Then, I commited the container (with the imported sql) as a new container image

sudo docker commit -m "Imported liferay sql dump" <id-of-the-container> jihedamine/mysql-psat1:v1

但是,如果我使用该新映像启动容器,则mysql数据库不包含新创建的数据库liferay_psat1.

However, when if I start a container using that new image, the mysql database doesn't contain the newly created database liferay_psat1.

sudo docker run -ti jihedamine/mysql-psat1:v1 bash
> mysql -uroot -psecret
# show databases;

我在做什么错了?

感谢您的帮助!

推荐答案

正式的mysql映像将数据存储在一个卷中.通常,这样做是希望的,以便您的数据可以保留到容器的生命周期之外,但是数据卷会绕过Union File System,并且不会提交到映像.

The official mysql image stores data in a volume. Normally this is desired so that your data can persist beyond the life span of your container, but data volumes bypass the Union File System and are not committed to the image.

您可以通过创建自己的没有卷的mysql基本映像来完成您要执行的操作.这样,您就可以添加数据并将其提交到映像,但是当容器消失时,提交后添加到正在运行的容器中的任何数据都将丢失.

You can accomplish what you're trying to do by creating your own mysql base image with no volumes. You will then be able to add data and commit it to an image, but any data added to a running container after the commit will be lost when the container goes away.

这篇关于在mysql容器中提交数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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