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

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

问题描述

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

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 官方镜像将数据存储在一个卷中.通常,这是需要的,以便您的数据可以在容器的生命周期之外持续存在,但数据量绕过联合文件系统并且不会提交到映像.

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天全站免登陆