将数据提交到新图像后,Mysql docker 容器中的数据丢失了吗?
Data is lost in Mysql docker container after comminting it to a new image?
我从 docker 集线器中提取了一个 mysql 基础映像,并从该映像中提取了一个容器 运行 并在该容器中创建了一个数据库和一些表,并将更改提交到新图片。但是当我 运行 我的新图像的容器时,没有我创建的数据库。如何做到这一点?我不想使用已安装的卷,因为我想 link 这个容器与我的应用程序的另一个容器,以便它可以插入并更新到 db 中。
我不知道您使用的是哪个图像,但我相信 official mysql images 的每个 Dockerfile
都有以下命令:
VOLUME /var/lib/mysql
这意味着所有 mysql 数据都进入了卷。来自 docker volume docs 他们特别提到:
> Changes to a data volume will not be included when you update an image.
这就是您在新启动的容器中丢失数据的根本原因。
对于你的问题:
How to achieve this?
您可以使用 mounted volumes, or create a data volume container,然后使用带有选项 --volumes-from
的 运行 mysql 容器。前 link 包含有关操作方法的分步指南。
I don't want to use mounted volumes because i want to link this container with another container of my application so that it can inset and update into db
我不知道您对挂载卷还有什么其他顾虑,但据我所知,使用挂载卷不会阻止您使用 link 容器。
希望对您有所帮助。
我从 docker 集线器中提取了一个 mysql 基础映像,并从该映像中提取了一个容器 运行 并在该容器中创建了一个数据库和一些表,并将更改提交到新图片。但是当我 运行 我的新图像的容器时,没有我创建的数据库。如何做到这一点?我不想使用已安装的卷,因为我想 link 这个容器与我的应用程序的另一个容器,以便它可以插入并更新到 db 中。
我不知道您使用的是哪个图像,但我相信 official mysql images 的每个 Dockerfile
都有以下命令:
VOLUME /var/lib/mysql
这意味着所有 mysql 数据都进入了卷。来自 docker volume docs 他们特别提到:
> Changes to a data volume will not be included when you update an image.
这就是您在新启动的容器中丢失数据的根本原因。
对于你的问题:
How to achieve this?
您可以使用 mounted volumes, or create a data volume container,然后使用带有选项 --volumes-from
的 运行 mysql 容器。前 link 包含有关操作方法的分步指南。
I don't want to use mounted volumes because i want to link this container with another container of my application so that it can inset and update into db
我不知道您对挂载卷还有什么其他顾虑,但据我所知,使用挂载卷不会阻止您使用 link 容器。
希望对您有所帮助。