简体   繁体   English

来自Docker容器的持久MySQL数据

[英]Persistent mysql data from docker container

How can I persist data from my mysql container? 如何从mysql容器中保存数据? I'd really like to mount /var/lib/mysql from the container to the host machine. 我真的很想将/ var / lib / mysql从容器安装到主机上。 This indeed creates the directory, but when I create data, stop my application, and start a new one with the mounted directory, nothing is there. 这确实创建了目录,但是当我创建数据时,停止我的应用程序,并使用已安装的目录启动一个新目录,没有任何内容。 I've messed around with giving the directory all permissions and changing the user and group to root but nothing seems to work. 我弄乱了赋予目录所有权限,并将用户和组更改为root,但似乎无济于事。 I keep seeing people saying to use a data container, but I don't see how that can work with Amazon ec2 container service (ECS), considering each time I stop and start a task it would create a new data container rather than use an existing one. 我一直看到有人说要使用数据容器,但是我看不到它如何与Amazon ec2容器服务(ECS)一起使用,考虑到每次我停止并启动任务时,它都会创建一个新的数据容器而不是使用现有的。 Please help. 请帮忙。 Thank you 谢谢

Simply run your containers with something like this: 只需使用以下内容运行容器:

docker run -v /var/lib/mysql:/var/lib/mysql -t -i <container_id> <command>

You can keep your host /var/lib/mysql and mount it to each one of the containers. 您可以保留主机/ var / lib / mysql并将其安装到每个容器中。 Now this is not going to work with EC2 Container service unless all of your servers that you use for containers map to a common /var/lib/mysql (Perhaps nfs mounted from a master EC2 instance) 现在,这将无法与EC2容器服务一起使用,除非用于容器的所有服务器都映射到通用的/ var / lib / mysql(也许是从主EC2实例挂载的nfs)

AWS EFS is going to be great for this once it becomes widely available. 一旦广泛可用, AWS EFS将对此非常有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM